Practice · 1 of 2
Prove the visibility bug
CHALLENGE
Difficulty: advanced+25 XP
Implement static int SpinUntilFlag(int ms) that busy-waits (Thread.Sleep(1) loop, bounded by ms) until a static bool Flag set by static void SetFlag() becomes true, returning 1 if seen, 0 on timeout — but read Flag through Volatile.Read so the JIT cannot cache it in a register. The test sets the flag from another thread mid-spin and expects success.
Press Submit to check your solution.
Back to lesson: Practice: Concurrency drills