Previous | Next --- Slide 12 of 37
Back to Lecture Thumbnails
jmc

This image illustrates the necessity of "hand-over-hand" locking: when traversing a linked list A->B->C, you have to maintain the lock on node B at least until you have obtained the lock on node C. For the American Ninja Warrior, this corresponds to: you have to keep holding onto bar B until you've grabbed bar C, then you can let go of B. If you release B before you've grabbed C, you will fall (disregarding momentum, etc.). On the linked list side, letting go of B before you've grabbed C is releasing the lock on B before acquiring the lock on C. This is a problem because once you've released B, you no longer have any guarantee on it (e.g. that its next pointer is valid, that it's still in the list, etc.) because other threads can change/delete it, and you end up with undefined behavior.