双重检查锁定在.NET [英] Double-checked locking in .NET

查看:165
本文介绍了双重检查锁定在.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到这个文章讨论为什么仔细检查锁定范例打破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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆