class to configure worker behavior in an executor More...
#include <taskflow/core/worker.hpp>
Public Member Functions | |
| virtual | ~WorkerInterface ()=default |
| default destructor | |
| virtual void | scheduler_prologue (Worker &worker)=0 |
| method to call before a worker enters the scheduling loop | |
| virtual void | scheduler_epilogue (Worker &worker, std::exception_ptr ptr)=0 |
| method to call after a worker leaves the scheduling loop | |
class to configure worker behavior in an executor
The tf::WorkerInterface class allows users to customize worker properties when creating an executor. Examples include binding workers to specific CPU cores or invoking custom methods before and after a worker enters or leaves the work-stealing loop. When you create an executor, it spawns a set of workers to execute tasks with the following logic:
The example below demonstrates the usage of tf::WorkerInterface to affine a worker to a specific CPU core equal to its id on a Linux platform:
When running the program, we see the following one possible output:
|
pure virtual |
method to call after a worker leaves the scheduling loop
| worker | a reference to the worker |
| ptr | an pointer to the exception thrown by the scheduling loop |
The method is called by the scheduler after leaving the work-stealing loop. Any uncaught exception during the worker's execution will be propagated through the given exception pointer.
|
pure virtual |
method to call before a worker enters the scheduling loop
| worker | a reference to the worker |
The method is called by the scheduler before entering the work-stealing loop.