Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2019 optimize code in release mode broken?

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?

like image 540
Alexey Klipilin Avatar asked Aug 28 '19 13:08

Alexey Klipilin


People also ask

Can I debug in release mode?

You can now debug your release build application. To find a problem, step through the code (or use Just-In-Time debugging) until you find where the failure occurs, and then determine the incorrect parameters or code.

How do I disable code optimization in Visual Studio 2019?

Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > C/C++ > Optimization property page. Modify the Optimization property.

How do I run a Visual Studio code in release mode?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).

What is the difference between debug and release mode in Visual Studio?

By default, Debug includes debug information in the compiled files (allowing easy debugging) while Release usually has optimizations enabled. As far as conditional compilation goes, they each define different symbols that can be checked in your program, but they are language-specific macros.


1 Answers

Thank you for reporting this issue.

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

like image 52
Brian Sullivan Avatar answered Nov 03 '22 14:11

Brian Sullivan