Loading lesson…
Level 1 · Apprentice0 XP
Locks, waiting threads, and the forgotten problem: visibility.
Step 1 / 6
ProblemA bank transfer takes money from A and adds it to B. Two separate atomics are not enough: another thread could see the money gone from A but not yet in B.
← → step
Before this: From count++ to the atomic CPU instruction
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Write a loop that spins on a plain Boolean flag set by another thread after 100 ms. Check whether it stops reliably; then add @Volatile and compare. Finally, implement transfer with synchronized and check that the total stays 100 under 8 threads.