One embodiment of the present invention provides a system that facilitates
applying a dynamic lock to a range of a resource within a computer
system. Upon receiving a request to lock to the range of the resource
from a thread, the system examines an active lock pool to determine if
the range of the resource is currently locked. If not, the system
retrieves a dynamic lock from a free lock pool. Next, the system sets
resource information in the dynamic lock so that the dynamic lock is
associated with the resource. The system also sets owner information in
the dynamic lock so that the dynamic lock is associated with the thread
that is requesting the dynamic lock. Finally, the system adds the dynamic
lock to the active lock pool.