You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NOTE:Most likely this does not just affect Interlocked.Exchange, but it's easy to reproduce this way.
When turning on the optimization for the following code you get different (and also wrong) output values than from building the application without turning on the optimizer.
usingSystem;usingSystem.Threading;classProgram{privatestaticint_intToExchange=-1;privatestaticshort_innerShort=2;staticvoidMain(string[]args){varoldValue=Interlocked.Exchange(ref_intToExchange,_innerShort);Console.WriteLine("It was: {0}",oldValue);Console.WriteLine("It is: {0}",_intToExchange);Console.WriteLine("Expected: {0}",_innerShort);}}
Without using optimization the output is as expected:
It was: -1
It is: 2
Expected: 2
But when you turn on optimization (e.g. with <Optimize>true</Optimize> in .csproj) this is the output:
It was: 65535
It is: -65534
Expected: 2
More about this bug can also be found here on stackoverflow.
The text was updated successfully, but these errors were encountered:
NOTE: Most likely this does not just affect Interlocked.Exchange, but it's easy to reproduce this way.
When turning on the optimization for the following code you get different (and also wrong) output values than from building the application without turning on the optimizer.
Without using optimization the output is as expected:
But when you turn on optimization (e.g. with
<Optimize>true</Optimize>
in .csproj) this is the output:More about this bug can also be found here on stackoverflow.
The text was updated successfully, but these errors were encountered: