Thread Safety with Phaser, StampedLock and VarHandle
summary
Compares Phaser, StampedLock and VarHandle with code and microbenchmarks: starting threads via volatile spin, wait/notify, CountDownLatch and phaser arrive and awaitAdvance finds Phaser gives sub-10µs max skew and far lower total delay than others. Shows StampedLock optimistic reads with StampedLock.tryOptimisticRead plus validate and fallback to readLock to preserve invariants. Replaces locks with VarHandle-backed CAS on a double[] (using VarHandle compareAndSet), yielding ~88M move ops and ~55M distance ops, beating stamped locks and synchronized in these tests.
AI-written summary · about
chapters (7)
- 0:00Start
- 11:41Countdown Latch
- 18:15Stamped Lock
- 20:00Stamp Lock
- 24:45Validate the Stamp
- 37:56Var Handles
- 45:03Here's Not the Reason Why Matthews in Jaya Match for this Is Jh Will Need a Long Warm Up So Contrary To Do that as a Demo Here I Can Only Show You the Results Not So Much Fun like like Seeing the Answers Here So I'M Going To Just Copy and Paste these Values in Here so We We Have those and Then We'Re Going To Refactor this To Use Var Handles Now Let's Get Rid of this Temp Lock and We Get To Do this all with Four Handles
related talks
52mThread Safety with Phaser, StampedLock and VarHandle.
01h 14mThread Safety with Phaser, StampedLock and VarHandle
47mThread Safety with Phaser, StampedLock, and VarHandle
47mUsing Java 8 Lambdas and Stampedlock to manage thread safety
45mThe Hidden Art of Thread-Safe Programming: Exploring java.util.concurrent
41mJava 9 VarHandles Best practices, and why?
50mThe Hidden Art of Thread-Safe Programming: Exploring java.util.con...
52mSTM and Structured Concurrency — The Battle with Multithreading Dragons
