Use Builtin Atomics for wait/waitAsync/notify#956
Conversation
4482ead to
4a0935d
Compare
| pub struct SharedDataBlock { | ||
| ptr: RacyPtr<u8>, | ||
| max_byte_length: SharedDataBlockMaxByteLength, | ||
| waiters: Option<SharedWaiterMap>, |
There was a problem hiding this comment.
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.
Fix: #899