Skip to content

fix(condvar): align notifications with standard semantics - #132

Merged
tisonkun merged 3 commits into
mainfrom
codex/posix-condvar-semantics
Aug 1, 2026
Merged

fix(condvar): align notifications with standard semantics#132
tisonkun merged 3 commits into
mainfrom
codex/posix-condvar-semantics

Conversation

@tisonkun

@tisonkun tisonkun commented Aug 1, 2026

Copy link
Copy Markdown
Member

Summary

  • replace the semaphore-backed Condvar state with a fair FIFO waiter queue
  • make notify_one and notify_all affect only tasks that are currently waiting
  • register each waiter before releasing its mutex guard to preserve the atomic wait handoff
  • pass a notify_one wakeup to another current waiter when the selected wait is cancelled before reacquiring the mutex
  • document predicate-based usage and cover non-buffering, one/all wakeups, cancellation, and owned waits

Testing

  • cargo x lint
  • cargo x test --no-capture
  • cargo test --workspace --all-targets
  • cargo +1.85.0 test --workspace --no-default-features

Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reworks Condvar to follow standard condition-variable semantics (non-buffered notifications) while preserving fairness via a FIFO waiter queue, and adds documentation/tests to lock in the new behavior.

Changes:

  • Replace the semaphore-backed Condvar state with an internal FIFO waiter queue and explicit waiter state tracking.
  • Update the internal WaitList API to support unlink-then-remove semantics and adapt Semaphore to the new API.
  • Add targeted Condvar tests for non-buffered notifications, notify-one/all behavior, and cancellation handoff; update README/CHANGELOG to reflect the new semantics.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Updates Condvar description to match FIFO + non-buffered semantics.
mea/src/internal/waitlist.rs Refactors wait list into a sentinel-based list with explicit unlink/remove operations.
mea/src/internal/semaphore.rs Migrates semaphore waiter handling to the new WaitList::unlink_* / remove_unlinked_waiter API.
mea/src/condvar/tests.rs Adds coverage for standard condvar notification semantics and cancellation behavior.
mea/src/condvar/mod.rs Implements the new FIFO, non-buffered Condvar with cancellation-aware notify-one baton passing.
CHANGELOG.md Notes the user-visible semantic change to Condvar notifications and cancellation behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mea/src/condvar/tests.rs
@tisonkun
tisonkun merged commit 3587a67 into main Aug 1, 2026
10 checks passed
@tisonkun
tisonkun deleted the codex/posix-condvar-semantics branch August 1, 2026 11:12
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.

2 participants