When I run the following code in debug mode, it will complete successfully and complete. However, if I run the following code in release mode, it will get stuck in an infinite loop and never end.
static void Main(string[] args) { bool stop = false; new Thread(() => { Thread.Sleep(1000); stop = true; Console.WriteLine("Set \"stop\" to true."); }).Start(); Console.WriteLine("Entering loop."); while (!stop) { } Console.WriteLine("Done."); }
What kind of optimization makes it stuck in an infinite loop?
nivlam May 25 '12 at 4:16 2012-05-25 04:16
source share