Skip to content

Add FiberCondVar - #51

Merged
vadimskipin merged 4 commits into
mainfrom
vskipin/condvar
May 27, 2026
Merged

vadimskipin merged 4 commits into
mainfrom
vskipin/condvar

Conversation

@vadimskipin

Copy link
Copy Markdown
Collaborator

Implements a fiber-aware condition variable with notify_one/notify_all semantics. wait() atomically releases the protecting lock and suspends, re-acquiring before return; wait_for() adds a nanosecond-bounded variant.

When handleExpiredWaitersSlow ran its tree.remove() before clearing
IN_TABLE, a concurrent cancelSleep could observe state with IN_TABLE
still set, push to cancelQueue, then handleCancelQueueSlow on the next
iteration would call tree.remove() again on the already-removed node --
corrupting the rbtree and SEGV'ing on the next iterator walk.
The relaxed-spin + acquire-fence pattern is correct under the C++ memory
model but TSan does not track HB through standalone acquire fences. Under
TSan, replace the fence with an acquire-load on the counter so the
release-acquire pair on this atomic is directly visible to the tool; the
prior TSAN_RELEASE/TSAN_ACQUIRE side-channel annotations on waitState
become unnecessary. Production keeps the fence -- no extra atomic op on
weak archs.
Implements a fiber-aware condition variable with notify_one/notify_all
semantics. wait() atomically releases the protecting lock and suspends,
re-acquiring before return; wait_for() adds a nanosecond-bounded variant.
@vadimskipin
vadimskipin marked this pull request as ready for review May 27, 2026 16:30
@vadimskipin
vadimskipin merged commit 53b8a1c into main May 27, 2026
27 of 28 checks passed
@vadimskipin
vadimskipin deleted the vskipin/condvar branch May 27, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant