 | | This is all well and good, but beware! If we now allow threads to acquire these locks in any order they please, the kind of deadlock known as a deadly embrace can occur. For example, consider two threads that intend to lock the same section of the tree (see Figure 3-3).The first thread tries to obtain the L1, L2, and L3 locks in succession, and the second thread goes after L3, L2, and L1 in the reverse order at the same time. If their execution overlapped, it's quite possible that each would stall waiting for a lock already held by the other. (Here, the first thread blocks waiting for the L3 lock that the second thread holds, and the second thread blocks waiting for the L2 lock that the first thread holds.) Our threads are deadlocked waiting for each other. | |
|