summaryrefslogtreecommitdiff
path: root/scheduler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scheduler.cpp')
-rw-r--r--scheduler.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/scheduler.cpp b/scheduler.cpp
index 452b0bb..6ed66ac 100644
--- a/scheduler.cpp
+++ b/scheduler.cpp
@@ -2,6 +2,7 @@
#include <chrono>
#include <cassert>
#include "scheduler.h"
+#include "params.h"
void Scheduler::workerEntry() {
while (true) {
@@ -16,10 +17,22 @@ void Scheduler::workerEntry() {
}
if (job) {
+ if (scheduler_verbose) {
+ cout << "SCHED(" << this_thread::get_id() << ") running job" << endl;
+ }
job->callback();
+ if (scheduler_verbose) {
+ cout << "SCHED(" << this_thread::get_id() << ") finished job" << endl;
+ }
} else if (finishFlag) {
+ if (scheduler_verbose) {
+ cout << "SCHED(" << this_thread::get_id() << ") spotted finishFlag" << endl;
+ }
break;
} else {
+ if (scheduler_verbose) {
+ cout << "SCHED(" << this_thread::get_id() << ") no job, waiting" << endl;
+ }
this_thread::sleep_for(chrono::milliseconds(100));
}
}
@@ -34,6 +47,10 @@ Scheduler::Scheduler(int nthreads)
for (int i = 0; i < nthreads; i++) {
workers.emplace_back([this]() { workerEntry(); });
}
+
+ if (scheduler_verbose) {
+ cout << "SCHED " << nthreads << " workers spawned" << endl;
+ }
}
Scheduler::~Scheduler() {
@@ -49,14 +66,25 @@ void Scheduler::submit(const function<void()> &func) {
void Scheduler::finish() {
if (hasJoined) return;
+ if (scheduler_verbose) {
+ cout << "SCHED finish()" << endl;
+ }
+
{
lock_guard commMutGuard(commMut);
finishFlag = true;
}
for (int i = 0; i < nthreads; i++) {
+ if (scheduler_verbose) {
+ cout << "SCHED Joining worker " << i << "..." << endl;
+ }
workers[i].join();
}
+ if (scheduler_verbose) {
+ cout << "SCHED All workers joined" << endl;
+ }
+
hasJoined = true;
}