Fix bthread_join memory visibility with paired release/acquire on version_butex - #3538
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Resolve the remaining version_butex data race and add the requested regression test.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes bthread_join memory visibility by pairing release publication with acquire observation on version_butex.
Changes:
- Atomically publishes version updates at task completion.
- Uses acquire loads during joining.
- Documents synchronization semantics.
File summaries
| File | Summary |
|---|---|
src/bthread/task_meta.h |
Updates version synchronization documentation. |
src/bthread/task_group.cpp |
Implements release/acquire handling; TaskGroup::exists() still has an unresolved plain-read race, and a visibility regression test is requested. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
chenBright
force-pushed
the
fix_bthread_join_fence
branch
from
September 13, 2026 05:31
cd503e0 to
30e9934
Compare
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.
What problem does this PR solve?
Issue Number: resolve #3274
Problem Summary:
The join/end handshake on
version_butexwas not correctly synchronized.task_runner, at bthread end): bumped the version with a plain write++*m->version_butex. The surroundingversion_lockprovides release semanticsonly to threads that also take that lock, but
join()does not, so there is no release onversion_butexfor the join path.TaskGroup::join): exited its wait loop via a plain read*m->version_butex,with no acquire ordering.
The result is a data race with no happens-before edge, so writes the joined bthread made
before ending were not guaranteed visible after
join()returned. On x86 (TSO) the hardwaremasked this, but on ARM it surfaced.
PR #3276 attempted a fix by adding a lone
atomic_thread_fence(acquire)after the loop. Butper the C++ memory model an acquire fence only establishes synchronization when a preceding
atomic load reads a value from a matching release operation. Here the load was a plain read and
the producer had no release store, so the fence pairs with nothing. It happens to work on ARM
only because the compiler emits a real
dmb ishld, not because the model guarantees it.What is changed and the side effects?
Changed:
This PR replaces that band-aid with a properly paired release/acquire on
version_butex.Side effects:
Performance effects:
Breaking backward compatibility:
Check List: