Kirk Krauss is a software developer working on IBM Rational
PurifyPlus. "People with ropes around their necks don't always
hang." -- Lee van Cleef in The Good, the Bad, and the Ugly In
today's world of multicore computing, it's important to make
sure that your multithreaded applications scale. A longstanding
approach for making the most of multiple processors is to
arrange for different resources to be protected by different
synchronization objects, or locks. A drawback of this approach
is that a bug in your threading model can lead to a deadlock.
Given the complexity of modern applications, particularly where
routines can call back and forth between one another, you have
to be very careful to avoid the situation where two or more
threads can get stuck waiting for locks held by each other. If
two threads take two locks, and each then waits for the lock
held by the other, a classic deadlock begins. As an example,
consider a program that has two threads, T1 and T2, and two
locks, L1 and L2. A deadlock occurs in