简体   繁体   中英

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. 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.

Also, you don't understand what volatile does . Volatile is to prevent blocking, not to cause blocking.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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