diff options
Diffstat (limited to 'competition/job.h')
-rw-r--r-- | competition/job.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/competition/job.h b/competition/job.h new file mode 100644 index 0000000..9dba159 --- /dev/null +++ b/competition/job.h @@ -0,0 +1,39 @@ +#pragma once + +#include <functional> +#include <queue> +#include <vector> +#include <thread> +#include <mutex> + +using namespace std; + + +class Scheduler { + struct Job { + function<void()> callback; + + Job(const function<void()> callback) + : callback(callback) {} + }; + + queue<Job*> jobs; + bool terminateFlag = false; + mutex commMut; + + vector<thread> workers; + + void workerEntry(); + +public: + const int nthreads; + + Scheduler(int nthreads); + ~Scheduler(); + + // func is run in child thread + // doneCallback is run in host thread + void submit(const function<void()> &func); + + void finish(); +}; |