forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker_interface.cpp
More file actions
30 lines (22 loc) · 820 Bytes
/
worker_interface.cpp
File metadata and controls
30 lines (22 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// This program demonstrates how to change the worker behavior
// upon the creation of an executor.
#include <taskflow/taskflow.hpp>
class CustomWorkerBehavior : public tf::WorkerInterface {
public:
// to call before the worker enters the scheduling loop
void scheduler_prologue(tf::Worker& w) override {
std::cout << tf::stringify(
"worker ", w.id(), " (native=", w.thread()->native_handle(), ") enters scheduler\n"
);
}
// to call after the worker leaves the scheduling loop
void scheduler_epilogue(tf::Worker& w, std::exception_ptr) override {
std::cout << tf::stringify(
"worker ", w.id(), " (native=", w.thread()->native_handle(), ") leaves scheduler\n"
);
}
};
int main() {
tf::Executor executor(4, std::make_shared<CustomWorkerBehavior>());
return 0;
}