-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Arc::strong_count memory ordering is a potential footgun #117485
Copy link
Copy link
Open
Labels
A-atomicArea: Atomics, barriers, and sync primitivesArea: Atomics, barriers, and sync primitivesC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-atomicArea: Atomics, barriers, and sync primitivesArea: Atomics, barriers, and sync primitivesC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
In #115546 the memory ordering of
{Arc,Weak}::{strong,weak}_countgot changed toRelaxed, which can cause some hard to debug race bugs.I tried this code:
I expected to see this happen: I expected the check
strong_count == 0to be strong enough to avoid a data race in this program. My intuition was that this check implies that no other thread can access the data concurrently.Instead, this happened: With the fence commented out, the above program has undefined behavior. Miri outputs:
I think we should either put the
Acquireordering back or add a warning to the docs that such code requires a manual fence.Meta
1.74 = current beta
cc @SUPERCILEX author of #115546
@rustbot label T-libs A-atomic