
Part: 18.13 Volatile Variables
In order to rectify this situation we declare variables to be volatile in order to disable register optimisations:
// Shared variable volatile int i2; // The same functions as above but use a volatile variable. // Not optimised anymore so results are always correct. void FV1() { while (true) i2++; } void FV2() { while (true) cout<<i2<<endl; }
This is so wrong!
Please explain why this is wrong. Is the code wrong? Is the example wrong? Please note that this is a snippet from the full test program where two different threads are started to execute FV1() and FV2(). On my dual-core machine the version without volatile produces wrong results while the version with volatile produces correct results. Daniel _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost