首先咱们可以看一下MSDN对volatile的定义: The volatile keyword indicates that a field can be modified in the program by something such as the operating system, the hardware, or a concurrently executing thread.
The system always reads the current value of a volatile object at the point it is requested, even if the previous instruction asked for a value from the same object. Also, the value of the object is written immediately on assignment.
The volatile modifier is usually used for a field that is accessed by multiple threads without using the lock statement to serialize access. Using the volatile modifier ensures that one thread retrieves the most up-to-date value written by another thread. 然后呢,咱们可以看到在Singleton模式中对多线程的优化
posted on 2007-11-12 12:36 逖靖寒 阅读(3847) 评论(6) 编辑 收藏 网摘 所属分类: 读书.NET 编程
昵称: [登录] [注册]
主页:
邮箱:(仅博主可见)
验证码: 看不清,换一个
评论内容:
登录 注册
[使用Ctrl+Enter键快速提交评论]