I have a variable which is shared between several threads (assuming suitable sync method is in place).
Should I define the variable as volatile?
The reason that I am asking is: Any of the following can be the answer:
yes: Since the variable can be change by a thread and other thread should be aware of it.
no: Since compiler can understand that a value for a variable is on CPU memory and it doesn't matter which thread wants to read it, compiler would take care of it.