title: Debug vs Release C# code
body: <p>I have the following code:</p>
  
  <pre><code> public static void Main(string[] args)
      {
          bool isComplete = false;
  
          var t = new Thread(() =&gt;
          {
              int i = 0;
              while (!isComplete) i += 0;
          });
  
          t.Start();
  
          Thread.Sleep(500);
          isComplete = true;
          t.Join();
          Console.WriteLine("complete!");
  
      }
  </code></pre>
  
  <p>The program will hung in release mode and will give an output in debug mode ("complete!").</p>
  
  <p>What is the reason for that?</p>
  
  <p>Thanks.</p>