[API Proposal]: System.Threading.Relaxed.Read #75874
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Threading
memory model
issues associated with memory model
Milestone
Background and motivation
Unlike
System.Threading.Volatile.Read
, theSystem.Threading.Relaxed.Read
only defeats compiler optimizations.This is basically an official
VolatileReadWithoutBarrier
(see:runtime/src/libraries/System.Threading/tests/InterlockedTests.cs
Line 682 in 118a162
The read will keep its order with respect to other memory operations (in singlethreaded/program order, not in the order of sideeffects), and used reads will not be coalesced with other reads from the same location.
Such read would be paired with
Interlocked.MemoryBarrierProcessWide
or could be used to poll a local that could be changed on another thread.A
Volatile.Read
could be used for the same purpose, but will add unnecessary guarantees of the order of the actual read.We can, optionally, add a requirement that the read is atomic.
A better name than "Relaxed" may exist too.
API Proposal
API Usage
Alternative Designs
Can use
Volatile.Read
or hand-written uninlinable methods with sole purpose of reading some variable.Risks
No risk, this is completely additive API.
The text was updated successfully, but these errors were encountered: