How do I atomically swap 2 ints in C#?

后端 未结 8 761
执念已碎
执念已碎 2020-11-29 06:50

What (if any) is the C# equivalent of the x86 asm xchg instruction?

With that command, which imo is a genuine exchange (unlike Interlocked.Exchange), I

8条回答
  •  情深已故
    2020-11-29 07:00

    According to MSDN, Interlocked.Exchange is atomic.

    If it is not suitable for you, you could implement XCHG in an unsafe section using C/C++.

提交回复
热议问题