2011-11-24 28 views

回答

3

您需要查看System.Threading命名空間中的Interlocked類。 CompareExchange是你正在尋找的方法。

它的格式爲CompareExchange(target, value, comparand),其中僞代碼表示if(target==comparand) target=value;

Interlocked類中還有其他一些有用的原子方法,例如Increment,Decrement,Add和Exchange。

相關問題