摘要 |
A method and apparatus for managing latches that protect resources is provided. A group of resources is divided into a plurality of subgroups of resources. Each subgroup of resources is provided its own latch. The latches for the subgroups of resources are ordered. When a process requires access to more than one subgroup of resources, the process acquires the latches for the subgroups in an order that is based on the order of the latches. By using these access techniques, processes may simultaneously access different subgroups of the group of resources without the possibility of deadlock. A process that requires all subgroups within a group of resources acquires a parent latch associated with the group of resources. The process then acquires the latches for each subgroup in a sequence that is based upon the order of the latches. As the process acquires each new latch, the process updates a current position value in the parent latch to indicate the most-recently-acquired latch. The current position value may be used by a cleanup entity in case the process dies prematurely. After acquiring all of the latches, the process releases the latches in reverse order, and updates the current position value as each latch is released. Thus, the current position value may be used for cleanup whether the process dies while attempting to acquire all latches or while releasing all latches.
|