Gentle Intro. to Lock-Free Programming in Java
summary
Explains concrete lock-free techniques: using a CAS loop to retry updates, implementing a Michael–Scott queue where enqueue uses two CAS steps (leading to tail lagging and a “helping” fix), and using AtomicMarkableReference or version tags to avoid ABA. Shows microbenchmarks where atomics reach several× the throughput of synchronized counters, discusses GC easing reclamation in Java vs manual free in C/C++, and uses JCStress to stress-test correctness under interleavings.
AI-written summary · about
chapters (15)
- 0:00Introduction and welcome
- 3:12What is lock-free programming
- 7:30Thread safety and atomic operations
- 12:49Atomic primitives and hardware
- 15:59Benchmarking atomic vs locks
- 17:45Compare-and-swap loops
- 19:10Michael Scott lock-free queue
- 25:55Testing with JCStress
- 29:09ABA problem explained
- 33:00Non-blocking lists and ABA fixes
- 36:58Java Memory Model with atomics
- 38:48When to use lock-free
- 41:00Problems with atomics
- 43:04Summary and recommendations
- 46:56Q&A and closing
