Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardC#volatile and memory barriersSingle-choice MCQ

In the classic Dekker-style pattern below, both flags are `volatile` yet both threads can still read the other's flag as false and enter the critical section. Why does volatile not prevent this on the .NET model?

// volatile bool _a, _b; // Thread 1: // Thread 2: _a = true; _b = true; if (!_b) { /*..*/ } if (!_a) { /*..*/ }