为什么静态方法线程安全自然. [英] why is static method thread safe natural.
问题描述
我对标题感到困惑.
Microsoft说他们的静态方法在.net中是线程安全的.
问题:1.只有内置的静态方法是方法吗?2.我们可以自定义静态方法而无需任何锁定或同步,这是线程安全的自然方法.
我对标题感到困惑.
Microsoft说他们的静态方法在.net中是线程安全的.
问题:1.只有内置的静态方法是方法吗?2.我们可以自定义静态方法而无需任何锁定或同步,这是线程安全的自然方法.
我不认为Microsoft实际上在任何地方都说过他们的静态方法是线程安全的,您能引用一个参考吗?
一个类并不是仅仅因为它是静态的就具有固有的线程安全性. 也许您指的是静态构造函数是线程安全的,因为它们只执行一次.
这是 C#语言规范.
类的静态构造函数在给定的应用程序域中最多执行一次.静态构造函数的执行由以下在应用程序域中发生的事件中的第一个触发:
- 已创建该类的实例.
- 该类的任何静态成员都被引用.
I am confused on the title.
Microsoft say their static method is thread safe in .net .
question:1. only build-in static method is method?
2. we can custom static method without any lock or sync, it is thread safe natural.
I am confused on the title.
Microsoft say their static method is thread safe in .net .
question:1. only build-in static method is method?
2. we can custom static method without any lock or sync, it is thread safe natural.
I don't believe that Microsoft actually says anywhere that their static methods are thread safe, can you cite a reference?
A class is not somehow inherently thread-safe just because it is static. Perhaps what you are referring to is the fact that static constructors are thread safe in that they execute only once.
Here's a relevant passage from the C# Language Specification.
The static constructor for a class executes at most once in a given application domain. The execution of a static constructor is triggered by the first of the following events to occur within an application domain:
- An instance of the class is created.
- Any of the static members of the class are referenced.
这篇关于为什么静态方法线程安全自然.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!