标签:重试 void ola and bsp sys vat nbsp wap
Compare And Swap 比较并交换 硬件同步原语
.NET通过 System.Threading.Interlocked.CompareExchang重载实现CAS
自旋锁CAS实现
public class SpinLock { private volatile int locked; public void Aquire() { while (System.Threading.Interlocked.CompareExchange(ref locked, 1, 0) != 0)
{
//‘浪费’CPU周期 重试
} } public void Release() { locked = 0; }
标签:重试 void ola and bsp sys vat nbsp wap
原文地址:https://www.cnblogs.com/fmys/p/9860739.html