Skip to content
Snippets Groups Projects
Commit cc870db9 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Merge branch 'notify_one_sleeping_worker' into 'master'

[Runtime] notify only one sleeping worker on new work

See merge request !60
parents 997386e7 c2686509
No related branches found
No related tags found
No related merge requests found
......@@ -66,7 +66,7 @@ Runtime::Runtime(workerid_t workerCount, RuntimeStrategy& strategy, unsigned int
threads(new pthread_t[workerCount]),
workers(new Worker*[workerCount]),
randomEngine(seed),
atLeastOneWorkerIsSleeping(false),
sleepingWorkers(0),
skipSleep(false) {
const int nprocs = get_nprocs();
......
......@@ -57,7 +57,7 @@ class Runtime : public Logger<LogSubsystem::RUNTI> {
ALIGN_TO_CACHE_LINE std::mutex workerSleepMutex;
std::condition_variable workerSleepConditionVariable;
ALIGN_TO_CACHE_LINE std::atomic<bool> atLeastOneWorkerIsSleeping;
ALIGN_TO_CACHE_LINE std::atomic<unsigned long> sleepingWorkers;
bool skipSleep;
static RuntimeStrategy& DEFAULT_STRATEGY;
......@@ -79,15 +79,15 @@ class Runtime : public Logger<LogSubsystem::RUNTI> {
// schedules another fiber, when this method will be called
// again. And then it is likely that the scheduling worker will
// observe the sleeping worker.
if (!atLeastOneWorkerIsSleeping.load(std::memory_order_relaxed)) {
if (!sleepingWorkers.load(std::memory_order_relaxed)) {
return;
}
}
std::lock_guard<std::mutex> lk(workerSleepMutex);
skipSleep = true;
atLeastOneWorkerIsSleeping = false;
workerSleepConditionVariable.notify_all();
sleepingWorkers.fetch_sub(1, std::memory_order_relaxed);
workerSleepConditionVariable.notify_one();
}
void dispatcherLoopSleep() {
......@@ -100,7 +100,7 @@ class Runtime : public Logger<LogSubsystem::RUNTI> {
// Check again if "skip sleep" has been set.
if (skipSleep) return;
atLeastOneWorkerIsSleeping = true;
sleepingWorkers.fetch_add(1, std::memory_order_relaxed);
workerSleepConditionVariable.wait(lk);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment