After some Googling and reading StackOverflow posts, it is not clear to me if marking a variable as volatile
makes it thread safe.
Does it?
After some Googling and reading StackOverflow posts, it is not clear to me if marking a variable as volatile
makes it thread safe.
Does it?
In a word - no.
Marking variable as volatile
addresses the problem of "safe publishing" where changes made to a variable by one thread are visible by all others (there are other ways of doing this too). There is no such guarantee when a variable is not volatile.
Safe publishing is but one one of the challenges of multi-threaded programming - there are others.