简体   繁体   English

非原始对象的挥发性等效项C#

[英]Volatile equivalent for non primitive objects c#

I think i'm missing something big here. 我想我在这里错过了一些大事。

What i'm trying to do: 我正在尝试做的是:

I have an object, which is known to multiple threads, which may read or manipulate it. 我有一个对象,多个线程都知道该对象,可以读取或操作它。 Now i want the object accesses to block, when one thread calls obj.setProperty(T type) i want every other thread to have to wait until the property is set. 现在,我希望对象访问被阻塞,当一个线程调用obj.setProperty(T type)时,我希望其他所有线程都必须等待,直到该属性被设置为止。 How to i do this? 我该怎么做? I know that there is volatile for primitive types, but how does this translate to non primitive types. 我知道原始类型有易失性,但是这如何转换为非原始类型。

Use the lock statement in the property getter and setter. 在属性getter和setter中使用lock语句。

Also, you don't understand what volatile does . 而且, 您不了解volatile的作用 Volatile is to prevent blocking, not to cause blocking. 挥发物是为了防止阻塞,而不是引起阻塞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM