Skip to content

Comments

Use Builtin Atomics for wait/waitAsync/notify#956

Draft
komyg wants to merge 1 commit intotrynova:mainfrom
komyg:fix/use-built-in-atomics
Draft

Use Builtin Atomics for wait/waitAsync/notify#956
komyg wants to merge 1 commit intotrynova:mainfrom
komyg:fix/use-built-in-atomics

Conversation

@komyg
Copy link
Contributor

@komyg komyg commented Feb 21, 2026

Fix: #899

@komyg komyg changed the title Create Parking Lot Mutex in SharedDataBlock Use Builtin Atomics for wait/waitAsync/notify Feb 21, 2026
@komyg komyg force-pushed the fix/use-built-in-atomics branch from 4482ead to 4a0935d Compare February 21, 2026 14:03
pub struct SharedDataBlock {
ptr: RacyPtr<u8>,
max_byte_length: SharedDataBlockMaxByteLength,
waiters: Option<SharedWaiterMap>,
Copy link
Member

Choose a reason for hiding this comment

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

thought (blocking): My thinking was that this would be within the RacyPtr allocation. See how the current byte length and reference count are accessed through ptr (left of ptr is normal Rust memory with the reference counts and others, at and right of it is racy memory which must not be read from Rust under any circumstances).

So my thinking was that the allocation for ptr would be one AtomicPtr<SharedWaiterMap> larger. That pointer would initially be 0 and then any thread using wait/waitAsync on a SharedDataBlock would perform an RCU update to change that into a pointer to an allocated SharedWaiterMap. If the RCU passes then you've successfully changed 0 to non-zero, and if it fails (non-supriously) then some other thread already changed it to non-zero, in which case you drop your own SharedWaiterMap and use the one that the other thread already RCU'd in. You also won't need an Arc over the Mutex in that case, as the reference counter inside the ptr takes care of that.

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.

Atomics wait/waitAsync/notify are not correct

2 participants