Locks, Atomics & Coordination

KOTLIN › JVM Concurrency

The full toolkit for shared mutable state, from immutability through atomics to locks, and the ways locks fail.

Interviewers ask "how would you make this thread-safe" and listen for whether you reach straight for a lock or work down a ladder. Expect to justify atomics over locking for a single value, explain compare-and-set and why it degrades under contention, cap concurrency with a Semaphore, and name the four conditions for deadlock along with which one lock ordering eliminates. Strong answers know that a monitor cannot be held across a suspending call, that Mutex is deliberately not reentrant, and that a read lock cannot be upgraded.

What this covers

Study this topic

Further reading