Thread safe Singleton in C#
来源:互联网 发布:专业编曲软件 编辑:程序博客网 时间:2024/05/22 10:33
public sealed class Singleton
{
private Singleton() {}
private static volatile Singleton _value;
private static object syncRoot = new Object();
public static Singleton Value
{
get
{
if (_value == null)
{
lock (syncRoot)
{
if (_value == null)
{
_value = new Singleton();
} //end inner if
} //end lock
} //end outer if
return _value;
} //end get
} //end Value
} //end class
• Double-check locking is used to ensure that exactly one instance is ever created and only when needed
• syncRoot is used to lock on rather than locking on the type itself to avoid deadlocks caused by outside code
• The _value instance is declared to be volatile in order to assure that the assignment to _value and any writes inside the Singleton constructor complete before the instance can be accessed
- Thread safe Singleton in C#
- [LinkedIn] singleton, thread safe
- muduo : Thread-safe Singleton
- Thread-Safe Singleton is Well Supported in C++11
- thread safe lazy initialization singleton
- Thread Safe In Servlet
- How to write a thread-safe Singleton?
- My Singleton in C#
- My Singleton in C#
- Singleton in C#
- Thread-safe, Signal-safe
- thread safe
- Singleton : Implementation in Unity3d C#
- Different types of thread-safe Sets in Java
- Java - How to write Thread-Safe Code in Java
- IOCP Thread Pool 在 C# 的Safe实现
- PHP Thread Safe and Non Thread Safe
- IOCP Thread Pooling in C#
- 使用随机hough变换(rht)进行圆的识别
- MySQL Reference Manual for version 4.1.0-alpha.
- Linux 内核模块
- asp + sqlserver 分页方法(不用存储过程)
- 如何封锁您的(或打开别人的) Java 代码
- Thread safe Singleton in C#
- Resources for Linux
- JAVA学习,是一条漫长的道路!
- [实用技巧]强制与别人的QQ聊天
- 使用ADO.NET 实现事务处理
- 第一次
- VB webbrowser 自动登陆问题 急!!!
- 成长中必须知道的20个故事
- 求解在SQL中使用了where列所遇到的问题