Skip to content

Commit

Permalink
Fix incorrect synchronization in private server (#739)
Browse files Browse the repository at this point in the history
* Fix a race in thread shutdown protocol

Signed-off-by: pavelkumbrasev <[email protected]>
  • Loading branch information
Pavel Kumbrasev authored Jan 26, 2022
1 parent 57f524c commit 525a388
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tbb/private_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ void private_worker::run() noexcept {
// Prepare to wait
my_thread_monitor.prepare_wait(c);
// Check/set the invariant for sleeping
if( my_state.load(std::memory_order_acquire)!=st_quit && my_server.try_insert_in_asleep_list(*this) ) {
// We need memory_order_seq_cst to enforce ordering with prepare_wait
// (note that a store in prepare_wait should be with memory_order_seq_cst as well)
if( my_state.load(std::memory_order_seq_cst)!=st_quit && my_server.try_insert_in_asleep_list(*this) ) {
my_thread_monitor.commit_wait(c);
__TBB_ASSERT( my_state==st_quit || !my_next, "Thread monitor missed a spurious wakeup?" );
my_server.propagate_chain_reaction();
Expand Down

0 comments on commit 525a388

Please sign in to comment.