C# compiler optimization and volatile keyword
问题 I have read some posts about volatile keyword and behaviour without this keyword. I've especially tested the code from the answer to Illustrating usage of the volatile keyword in C#. When running, I observe the excepted behaviour in Release mode, without debugger attached. Up to that point, there is no problem. So, as far as I understand, the following code should never exit. public class Program { private bool stopThread; public void Test() { while (!stopThread) { } // Read stopThread which