From 4d82d1ae95ee33dae80f71021ec15da03bcdde73 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Wed, 29 Aug 2018 22:54:41 +0200 Subject: Add scheduler debug logs --- params.h | 1 + scheduler.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) 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 #include #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 &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; } -- cgit v1.2.3-70-g09d2