Skip to content

Commit

Permalink
worker: fix hangup from two sequential wait() when a task is emplac…
Browse files Browse the repository at this point in the history
…ed before the `start()` signal

remove unnecessary start-flag and avoid additional `wait()` in startup of worker
  • Loading branch information
michaelsippel committed Dec 14, 2023
1 parent 0d58d87 commit 8e8e9a2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 22 deletions.
13 changes: 0 additions & 13 deletions redGrapes/dispatch/thread/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ WorkerThread::~WorkerThread()
void WorkerThread::start()
{
thread = std::thread([this]{ this->run(); });
this->Worker::start();
}

Worker::Worker( memory::ChunkedBumpAlloc<memory::HwlocAlloc> & alloc, HwlocContext & hwloc_ctx, hwloc_obj_t const & obj, WorkerId worker_id )
Expand All @@ -46,12 +45,6 @@ Worker::~Worker()
{
}

void Worker::start()
{
m_start.store(true, std::memory_order_release);
wake();
}

void Worker::stop()
{
SPDLOG_TRACE("Worker::stop()");
Expand Down Expand Up @@ -83,12 +76,6 @@ void WorkerThread::run()
};
*/

/* wait for start-flag to be triggerd in order
* to avoid premature access to `shared_from_this`
*/
while( ! m_start.load(std::memory_order_consume) )
cv.wait();

/* initialize thread-local variables
*/
SingletonContext::get().current_worker = this->shared_from_this();
Expand Down
10 changes: 1 addition & 9 deletions redGrapes/dispatch/thread/worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ struct Worker
//private:
WorkerId id;

/*!
* if true, the thread shall start
* executing the jobs in its queue
* and request rescheduling if empty
*/
std::atomic_bool m_start{ false };

/*! if true, the thread shall stop
* instead of waiting when it is out of jobs
*/
Expand Down Expand Up @@ -78,7 +71,6 @@ struct Worker
inline scheduler::WakerId get_waker_id() { return id + 1; }
inline bool wake() { return cv.notify(); }

void start();
virtual void stop();

/* adds a new task to the emplacement queue
Expand Down Expand Up @@ -133,7 +125,7 @@ struct WorkerThread
/* function the thread will execute
*/
void run();

void cpubind();
void membind();
};
Expand Down

0 comments on commit 8e8e9a2

Please sign in to comment.