Reputation:
Is there an equivalent for Interlocked.Exchange
for boolean?
Such as an atomic exchange of values that returns the previous value and doesn't require locks?
Upvotes: 11
Views: 2125
Reputation: 18340
No; use integers instead of booleans.
In principle such a thing could be written (cmpxchg, the underlying processor instruction, can operate on 8, 16, 32, and 64-bit operands on x86, 8, 16, 32, 64, and 128-bit operands on x64), but in practice most APIs stick to pointer and double pointer (32 and 64-bit on x86, 64 and 128-bit on x64) operands, because they're all you really need.
Upvotes: 8