Interlocked.CompareExchange
生活随笔
收集整理的這篇文章主要介紹了
Interlocked.CompareExchange
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
class SourceManager
{
private SourceManager() { }
private static SourceManager sourceManager;
public static SourceManager Instance
{
get
{
if (sourceManager == null)
{
/*
lock 實現方式
功能與以下 Interlocked.CompareExchange 相同
lock (this)
{
if (sourceManager == null)
{
sourceManager = new SourceManager();
}
}
*/
Interlocked.CompareExchange<SourceManager>(ref sourceManager, new SourceManager(), null);
}
return sourceManager;
}
}
}
轉載于:https://www.cnblogs.com/wolf12/p/4072483.html
總結
以上是生活随笔為你收集整理的Interlocked.CompareExchange的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 硬盘分区表知识
- 下一篇: DataGridView很详细的用法