Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 8d 09h 54m 32s8 days 9 hours 54 minutes 32 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 8d 09h 54m 32s8 days 9 hours 54 minutes 32 seconds.

Sign in to watch this lesson
Races and Locks · 4:36
Two threads swapping the same two objects in opposite orders each grab one mutex and wait forever for the other; we reproduce it on an Apple M3 with a watchdog thread (20 of 20 runs hung). We name the four conditions every deadlock needs, then remove them: std::scoped_lock takes several mutexes in one all-or-nothing step, a global lock order (by address, or one philosopher reaching right first) breaks the cycle, and a hierarchical mutex turns an ordering mistake into an immediate exception.