Should I declare WaitHandle(s) volatile?
Should WaitHandle
s 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
.
精彩评论