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?
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.
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.
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).
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.
Thank you for reporting this issue.
A fix for it is in the works and will be available shortly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With