开发者

Should I declare WaitHandle(s) volatile?

开发者 https://www.devze.com 2023-02-02 15:32 出处:网络
Should WaitHandles and other synchronization objects which are used by multipl开发者_JAVA技巧e threads be declared as volatile ?volatile is only relevant if you are re-assigning a field.

Should WaitHandles and other synchronization objects which are used by multipl开发者_JAVA技巧e threads be declared as volatile ?


volatile is only relevant if you are re-assigning a field.
For EventHandlers, the compiler will handle thread-safety; you shouldn't worry about it.

For other synchronization objects, you (probably) shouldn't be reassigning variables in the first place. (that's not the same as mutation)
Use readonly, not volatile.

0

精彩评论

暂无评论...
验证码 换一张
取 消