双重检查锁定在.NET

编程入门 行业动态 更新时间:2024-10-24 19:26:31
本文介绍了双重检查锁定在.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

本文发布于:2023-06-04 19:07:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/503339.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!