Skip to content
Permalink
Browse files

Remove 'started' bool from worker threads, as fixes for spurious wake…

…ups made it obsolete
  • Loading branch information...
CookiePLMonster committed Aug 10, 2019
1 parent 0639ffc commit 400a6f30576956b7b57222d65fa8f97659660ec1
Showing with 1 addition and 5 deletions.
  1. +0 −4 ext/native/thread/threadpool.cpp
  2. +1 −1 ext/native/thread/threadpool.h
@@ -6,7 +6,6 @@

WorkerThread::WorkerThread() {
thread.reset(new std::thread(std::bind(&WorkerThread::WorkFunc, this)));
while(!started) { };
}

WorkerThread::~WorkerThread() {
@@ -35,7 +34,6 @@ void WorkerThread::WaitForCompletion() {
void WorkerThread::WorkFunc() {
setCurrentThreadName("Worker");
std::unique_lock<std::mutex> guard(mutex);
started = true;
while (active) {
// 'active == false' is one of the conditions for signaling,
// do not "optimize" it
@@ -54,7 +52,6 @@ void WorkerThread::WorkFunc() {

LoopWorkerThread::LoopWorkerThread() : WorkerThread(true) {
thread.reset(new std::thread(std::bind(&LoopWorkerThread::WorkFunc, this)));
while (!started) { };
}

void LoopWorkerThread::Process(std::function<void(int, int)> work, int start, int end) {
@@ -69,7 +66,6 @@ void LoopWorkerThread::Process(std::function<void(int, int)> work, int start, in
void LoopWorkerThread::WorkFunc() {
setCurrentThreadName("LoopWorker");
std::unique_lock<std::mutex> guard(mutex);
started = true;
while (active) {
// 'active == false' is one of the conditions for signaling,
// do not "optimize" it
@@ -27,7 +27,7 @@ class WorkerThread {
std::condition_variable signal; // used to signal new work
std::condition_variable done; // used to signal work completion
std::mutex mutex, doneMutex; // associated with each respective condition variable
volatile bool active = true, started = false;
bool active = true;
int jobsDone = 0;
int jobsTarget = 0;
private:

0 comments on commit 400a6f3

Please sign in to comment.
You can’t perform that action at this time.