Lock ordering (source code)

= Lock ordering

A shared order governing acquisition of distinct <mutex> objects. To prevent circular waiting, choose a strict <total order> and acquire only a higher-ranked <mutex> while retaining lower-ranked ones. In the two-object <deadlock> example, every participant acquires A before B. An outline of the argument is that ranks would strictly increase around any alleged waiting cycle, yet return to the starting rank, a contradiction. The rule must include acquisitions hidden inside called routines. It excludes this kind of <deadlock>, not arbitrary waiting on other resources or failure to schedule an owner.<Operating Systems: Three Easy Pieces by Remzi H. Arpaci-Dusseau and others/Common Concurrency Problems>[pp. 7–8: consistent acquisition ordering and hidden calls]{ref}