14

For me it looks quite strange, and like a bug.
This code in Release mode in Visual Studio 2019 provides infinite loop.

class Program
{
    private static int _a;

    static void Main(string[] args)
    {
        _a = 1;
        while (_a == 1)
        {
            Console.WriteLine(_a);
            _a = 0;
        }
    }
}

volatile or Thread.MemoryBarrier(); (after _a = 0;) solves the issue. Don't think I had such issue with VS2015. Is this correct behavior? What exact part is optimized?

Alexey Klipilin
  • 1,866
  • 13
  • 29

1 Answers1

3

Thank you for reporting this issue.

A fix for it is in the works and will be available shortly.