diff options
author | tomsmeding <tom.smeding@gmail.com> | 2018-08-29 22:54:41 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2018-08-29 22:54:41 +0200 |
commit | 4d82d1ae95ee33dae80f71021ec15da03bcdde73 (patch) | |
tree | f267b8f9c88e78fc521819739dcba8ab389057ba | |
parent | 34ab0451bdd1e7496d607acb6ee209586ee7e86e (diff) |
Add scheduler debug logs
-rw-r--r-- | params.h | 1 | ||||
-rw-r--r-- | scheduler.cpp | 28 |
2 files changed, 29 insertions, 0 deletions
@@ -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; } |