I have a thread that sets a value to true when it is done. Until then I wait:
while(1)
{
if(done[0] == true)
{
break;
}
}
This code works just fine in Debug but in Release it stays in the loop forever even though the debugger clearly says that it is true and not false.
Why would this not work?
Thanks
This is symptomatic of not marking done as volatile.
Without volatile the optimising compiler can cache the value in a register.
e.g.
private volatile int i;
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