Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Interlocked.Exchange布尔值 是否有等价物?
Interlocked.Exchange
例如返回前一个值且不需要锁的值的原子交换?
不; 使用整数而不是布尔值。
原则上可以编写这样的东西(cmpxchg,底层处理器指令,可以在 x86、8、16、32、64 和 128 位操作数上操作 x64 上的 8、16、32 和 64 位操作数),但实际上,大多数 API 都坚持使用指针和双指针(x86 上为 32 位和 64 位,x64 上为 64 位和 128 位)操作数,因为它们是您真正需要的。