While going through many resources on multithreaded programming, reference to volatile specifier usually comes up. It is clear that usage of this keyword is not a reliable w
I found this DDJ article by Herb Sutter very interesting, especially how volatile is treated in C++, Java and C# .NET.
Dr.Dobbs volatile vs. volatile
Volatile variable should be used when that variable can be accessed by many threads and you want at every instruction your code should get the updated value of that variable.
Compilers generally optimize the code and store variables in register rather than getting from memory each and every time if they see no one has updated it.
But by using volatile you can force the compiler to get the updated value every time.