I\'ve seen this sentence:
the general rule is, if you have variables of primitive type that must be shared among multiple threads, declare those
I would propose a considerably more strict but very useful rule: if you do not understand exactly what volatile does, do not use it. Instead, use lock. If you do not understand exactly what lock does and how to use it, do not use multithreading.
volatile
lock