Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Concurrency-sensitive synchronization changes and a remaining changelog nit warrant final human review.
Pull request overview
Optimizes ManualResetEvent and AutoResetEvent state queries and immediately successful waits with atomic fast paths while preserving waiter and signal semantics.
Changes:
- Separates atomic event state from mutex-protected waiter management.
- Adds concurrency, cancellation, publication, and signal-consumption tests.
- Adds event benchmarks and changelog coverage.
File summaries
| File | Description |
|---|---|
tests-integration/tests/event_test.rs |
Extends manual-reset concurrency and reentrancy tests. |
tests-integration/tests/auto_reset_event_test.rs |
Adds auto-reset race and signal-consumption tests. |
CHANGELOG.md |
Documents the performance improvement; AutoResetEvent coverage should be added. |
benchmarks/asyncband/event/wait.rs |
Adds wait-path benchmarks. |
benchmarks/asyncband/event/mod.rs |
Registers event benchmarks. |
benchmarks/asyncband/event/auto_reset.rs |
Adds auto-reset benchmarks. |
asyncband/src/event/manual_reset.rs |
Adds atomic state fast paths. |
asyncband/src/event/auto_reset.rs |
Adds atomic signal consumption and state queries. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Let
ManualResetEvent::is_set,try_wait, and new waits that observe a set event complete without acquiring the waiter mutex. Preserve the public API and released waits across reset. Add readiness benchmarks and a cross-thread publication test over repeated set/reset cycles.Design Notes
All flag writes and waiter-list changes hold the same mutex; lock-free paths only read the flag.
setpublishes with Release and lock-free reads use Acquire.resetkeeps the writer lock and clears with Relaxed because clearing the flag does not publish data to successful waits.A wait that misses the fast path rechecks the flag under the lock before registering. Registered waits complete through their retained
WaitListnodes, so a later reset cannot revoke their release. The waiter list is stored directly in its mutex.Local single-thread M4 Max measurements of the retained manual-reset implementation compared with base
87017f9found already-set waits at 5.11 → 2.23 ns and registered wait/wake/reset cycles at 24.77 → 24.52 ns. Separate set/reset measurements showed roughly 1–2 ns of additional overhead. The optimization targets repeated readiness observations and already-set waits.Validation:
cargo x check,cargo x test,cargo x lint,cargo x bench --no-run, and the event benchmark smoke tests passed.Closes #252.