Skip to content

Commit 27c6465

Browse files
committed
Fix TSan race in blocking_context::enqueue
enqueue was calling impl_->cv.notify_one() outside the lock scope. A foreign thread could still be inside notify_one() when the main thread drained the queue, completed the task, saw signal_done, and destroyed the context. TSan flagged the read against cv during cond_signal after the waiter had released it. Move notify_one inside the lock_guard scope, matching signal_done. The race was latent before run() was switched to post on the return trip: no foreign thread ever called blocking_executor::post, so enqueue only ran on the pumping thread. testHopsBackToIoThread exercises a compute-pool worker posting back to blocking_executor via the return trampoline, which is what revealed the race under TSan.
1 parent d5a0406 commit 27c6465

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

src/test/run_blocking.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ void
8787
blocking_context::enqueue(
8888
std::coroutine_handle<> h)
8989
{
90-
{
91-
std::lock_guard<std::mutex> lock(impl_->mtx);
92-
impl_->queue.push(h);
93-
}
90+
std::lock_guard<std::mutex> lock(impl_->mtx);
91+
impl_->queue.push(h);
9492
impl_->cv.notify_one();
9593
}
9694

0 commit comments

Comments
 (0)