# tf::WorkerInterface class
#include <taskflow/core/worker.hpp>

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:

    for(size_t n=0; n<num_workers; n++) {
      create_thread([](Worker& worker)

        // pre-processing executor-specific worker information
        // ...

        // enter the scheduling loop
        // Here, WorkerInterface::scheduler_prologue is invoked, if any
        worker_interface->scheduler_prologue(worker);

        try {
          while(1) {
            perform_work_stealing_algorithm();
            if(stop) {
              break;
            }
          }
        } catch(...) {
          exception_ptr = std::current_exception();
        }

        // leaves the scheduling loop and joins this worker thread
        // Here, WorkerInterface::scheduler_epilogue is invoked, if any
        worker_interface->scheduler_epilogue(worker, exception_ptr);
      );
    }

#### Attention

tf::WorkerInterface::scheduler_prologue and tf::WorkerInterface::scheduler_eiplogue are invoked by each worker simultaneously.

## Constructors, destructors, conversion operators

~WorkerInterface() defaulted virtual
  default destructor

## Public functions

void scheduler_prologue(Worker& worker) pure virtual
  method to call before a worker enters the scheduling loop
void scheduler_epilogue(Worker& worker, std::exception_ptr ptr) pure virtual
  method to call after a worker leaves the scheduling loop

## Function documentation

### void tf::WorkerInterface::scheduler_prologue(Worker& worker) pure virtual

method to call before a worker enters the scheduling loop

Parameters
worker | a reference to the worker

The method is called by the constructor of an executor.

### void tf::WorkerInterface::scheduler_epilogue(Worker& worker, std::exception_ptr ptr) pure virtual

method to call after a worker leaves the scheduling loop

Parameters
worker | a reference to the worker
ptr | an pointer to the exception thrown by the scheduling loop

The method is called by the constructor of an executor.

Tab / T to search, Esc to close
…

Search for symbols, directories, files, pages or modules. You can omit any prefix from the symbol or file path; adding a `:` or `/` suffix lists all members of given symbol or directory.

Use ↓ / ↑ to navigate through the list, Enter to go. Tab autocompletes common prefix, you can copy a link to the result using ⌘ L while ⌘ M produces a Markdown link.

Sorry, nothing was found.