[API Proposal]: Interlocked.[Compare]Exchange
for bool
#100914
Labels
api-suggestion
Early API idea and discussion, it is NOT ready for implementation
area-System.Threading
Milestone
Background and motivation
Many times, I've found myself wanting to use
Interlocked.Exchange
on a single boolean flag. However, this is not possible, and I'm forced to use anint
with a zero or one.An API discrepancy exists where
Volatile.Read
andVolatile.Write
withbool
exist, but none forInterlocked
.Following #64658,
bool
overloads should be added.Theoretically, these can be implemented as wrappers around existing
Interlocked.[Compare]Exchange
throughUnsafe.As
.API Proposal
API Usage
Old code:
New code:
Alternative Designs
No response
Risks
None.
The text was updated successfully, but these errors were encountered: