Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
worker_pool.H File Reference

General-purpose worker thread pool for parallel task execution. More...

#include <thread>
#include <mutex>
#include <condition_variable>
#include <memory>
#include <ah-errors.H>
#include <tpl_arrayQueue.H>
#include <iostream>
Include dependency graph for worker_pool.H:

Go to the source code of this file.

Classes

class  WorkersSet< WorkerFct >
 Thread pool for parallel worker function execution. More...
 

Detailed Description

General-purpose worker thread pool for parallel task execution.

This file provides WorkersSet, a configurable thread pool that executes user-provided worker functions in parallel.

Features

  • Configurable number of worker threads
  • Generic worker function via template
  • Job completion signaling
  • Graceful shutdown

Usage Example

// Worker function: returns true when job is done
bool my_worker(void* params) {
auto* data = static_cast<MyData*>(params);
// Process data...
return data->is_last; // true stops all workers
}
WorkersSet<decltype(&my_worker)> pool(&my_worker, 100, 4);
// Schedule work items
for (auto& item : items) {
auto* data = new MyData(item);
pool.schedule_call(data);
}
pool.wait_until_all_workers_finished_or_job_is_done();
Thread pool for parallel worker function execution.
See also
q-consumer-threads.H Queue-based variant
Author
Leandro Rabindranath León

Definition in file worker_pool.H.