我碰到这个文章讨论为什么仔细检查锁定范例打破Java编写的。采用的是范式有效的.NET(特别是C#),如果变量声明挥发性?
I came across this article discussing why the double-check locking paradigm is broken in Java. Is the paradigm valid for .NET (in particular, C#), if variables are declared volatile?
推荐答案实现C#中的Singleton模式关于第三个版本的问题举行了会谈。
Implementing the Singleton Pattern in C# talks about this problem in the third version.
它说:
制作实例变量波动使它发挥作用,如将外显记忆障碍呼吁,虽然在后一种情况下,即使是专家不能同意到底哪些障碍是必需的。我倾向于尽量避免因专家不同意什么是对,什么是错的!
Making the instance variable volatile can make it work, as would explicit memory barrier calls, although in the latter case even experts can't agree exactly which barriers are required. I tend to try to avoid situations where experts don't agree what's right and what's wrong!
提交似乎暗示双锁是不太可能的工作比其他策略,因此,不应使用。
The author seems to imply that double locking is less likely to work than other strategies and thus should not be used.
更多推荐
双重检查锁定在.NET
发布评论