summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--params.h1
-rw-r--r--scheduler.cpp28
2 files changed, 29 insertions, 0 deletions
diff --git a/params.h b/params.h
index c3e6d5e..74c3db6 100644
--- a/params.h
+++ b/params.h
@@ -13,3 +13,4 @@ const int timeout_msec = 60000;
const bool multilog_fancy = true;
const bool referee_verbose = false;
+const bool scheduler_verbose = false;
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;
}