~/ learn/ comp-308/ cards/ volatile, atomics, and visibility
1 of 5

Type a volatile stop flag

Type a volatile stop flag

Answer

private volatile boolean running = true; public void stop() { running = false; }

volatile guarantees the worker thread sees the latest value of running, so the spin loop terminates when stop() is called.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/27f5163f-390e-4c37-893d-a9e195435bba/flashcard utf-8 LF