
Using the Volatile Keyword to Avoid Failures
When compiling a program, the compiler adds some optimizations that may cause your application to misbehave. For example consider the following code: // To avoid threads waiting on the critical section in vainif (m_instance == NULL){EnterCiriticalSection(pcs);if (m_instance == NULL)m_instance = new MyInstance();} The compiler may cache the second condition (m_instance