开发者

Should I declare WaitHandle(s) volatile?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜