【发布时间】:2013-02-18 12:37:23
【问题描述】:
是的,目前我正在学习 C# 语言规范和可能的可破译教程。我阅读了多个关于线程安全单例类的问题和答案/文章。
以下是我已经浏览过的帖子:
- Difference between static class and singleton pattern?
- Why use singleton instead of static class?
- Why choose a static class over a singleton implementation?
- how to make this c# class a singleton, thread safe
我读的越多,我就越沉迷于信息。有人可以指导我更好地了解
1) 为什么开发人员关心线程安全?
2) 如何确定静态类/单例类不是线程安全的? (试用示例代码/示例教程会很棒,因为我喜欢正确学习这些基础知识)
【问题讨论】:
-
这是一个安全或不安全的实现——不是“一般的单例”。
-
"why do developers care about thread-safety?"- 因为他们喜欢他们的代码,就像他们喜欢 thAsynchronous.eir 妙语一样。 -
@David 这是我见过的最好的解释。永远。
-
@David
thAsynchronous.eir punchlines这有点超出我的想象。你的意思是异步的吗?我只想知道线程环境中静态类带来的风险的正确图景。一个例子将不胜感激。
标签: c# static thread-safety singleton