Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top