Composite abortable locks
First Claim
Patent Images
1. A method for acquiring a lock associated with a shared resource, comprising:
- selecting, by a thread, a first node from a plurality of nodes preallocated for the lock, wherein the lock is configured to protect the shared resource such that the thread is required to acquire the lock prior to being able to access the shared resource, and wherein the plurality of nodes is constant and independent of a number of threads requesting the lock;
making a first node acquisition attempt, by the thread, to acquire the first node;
making a first node insertion attempt, by the thread, to insert the first node into a wait queue associated with the lock, upon success of the first node acquisition attempt;
acquiring the lock, by the thread, based on a position of the first node in the wait queue, upon success of the first node insertion attempt;
determining, by the thread, whether a first time period specified for the thread to acquire the lock has elapsed, upon failure of the first node acquisition attempt;
when the first time period has elapsed;
aborting, by the thread, any further attempts to acquire one of the plurality of nodes for the lock;
when the first time period has not elapsed;
waiting, by the thread, for a second time period;
when the first time period has not elapsed and the second time period has elapsed;
selecting, by the thread, a second node from the plurality of nodes for the lock; and
making, by the thread, a second node acquisition attempt to acquire the second node.
3 Assignments
0 Petitions
Accused Products
Abstract
A lock implementation has properties of both backoff locks and queue locks. Such a “composite” lock is abortable and is provided with a constant number of preallocated nodes. A thread requesting the lock selects one of the nodes, attempts to acquire the selected node, and, if successful, inserts the selected node in a wait-queue for the lock. Because there is only a constant number of nodes for the wait-queue, all requesting threads may not be queued. Requesting threads unable to successfully acquire a selected node may backoff and retry selecting and acquiring a node. A node at the front of the wait-queue holds the lock.
18 Citations
15 Claims
-
1. A method for acquiring a lock associated with a shared resource, comprising:
-
selecting, by a thread, a first node from a plurality of nodes preallocated for the lock, wherein the lock is configured to protect the shared resource such that the thread is required to acquire the lock prior to being able to access the shared resource, and wherein the plurality of nodes is constant and independent of a number of threads requesting the lock; making a first node acquisition attempt, by the thread, to acquire the first node; making a first node insertion attempt, by the thread, to insert the first node into a wait queue associated with the lock, upon success of the first node acquisition attempt; acquiring the lock, by the thread, based on a position of the first node in the wait queue, upon success of the first node insertion attempt; determining, by the thread, whether a first time period specified for the thread to acquire the lock has elapsed, upon failure of the first node acquisition attempt; when the first time period has elapsed; aborting, by the thread, any further attempts to acquire one of the plurality of nodes for the lock; when the first time period has not elapsed; waiting, by the thread, for a second time period; when the first time period has not elapsed and the second time period has elapsed; selecting, by the thread, a second node from the plurality of nodes for the lock; and making, by the thread, a second node acquisition attempt to acquire the second node. - View Dependent Claims (2, 3, 4, 5, 6, 7)
-
-
8. A system for providing concurrent access to a shared resource in a multi-threaded execution environment, comprising:
-
processor for executing instructions stored on a computer readable storage medium; the shared resource; and the computer readable storage medium, comprising; instructions for implementing a lock to protect the shared resource such that each one of a plurality of threads executing in the multi-threaded execution environment is required to acquire the lock prior to accessing the shared resource, comprising functionality to; allocate a plurality of nodes for the lock, wherein the plurality of nodes is constant and independent of the plurality of threads requesting the lock, and instantiate a wait queue for the lock; instructions for implementing each one of the plurality of threads, comprising functionality to; select a first node from the plurality of nodes for the lock; make a first node acquisition attempt to acquire the first node; make a first node insertion attempt to insert the first node into the wait queue, upon success of the first node acquisition attempt; acquire the lock based on a position of the first node in the wait queue, upon success of the first node insertion attempt; determine whether a first time period specified for each one of the plurality of threads to acquire the lock has elapsed, upon failure of the first node acquisition attempt; when the first time period has elapsed; abort any further attempts to acquire one of the plurality of nodes for the lock when the first time period has not elapsed; wait for a second time period; when the first time period has not elapsed and the second time period has elapsed; select a second node from the plurality of nodes for the lock; and make a second node acquisition attempt to acquire the second node. - View Dependent Claims (9, 10, 11)
-
-
12. A non-transitory computer readable storage medium comprising instructions for acquiring a lock associated with a shared resource, the instructions comprising functionality to:
-
select a first node from a plurality of preallocated nodes for the lock, wherein the lock is configured to protect the shared resource such that acquisition of the lock is required prior to being able to access the shared resource, and wherein the plurality of preallocated nodes is constant and independent of a plurality of threads requesting the lock; make a first node acquisition attempt to acquire the first node; make a first node insertion attempt to insert the first node into a wait queue associated with the lock, upon success of the first node acquisition attempt;
acquire the lock based on a position of the first node in the wait queue, upon success of the first node insertion attempt;determine whether a first time period specified to acquire the lock has elapsed, upon failure of the first node acquisition attempt; when the first time period has elapsed; abort any further attempts to acquire one of the plurality of preallocated nodes for the lock when the first time period has not elapsed; wait for a second time period; when the first time period has not elapsed and the second time period has elapsed; select a second node from the plurality of preallocated nodes for the lock; and make a second node acquisition attempt to acquire the second node. - View Dependent Claims (13, 14, 15)
make a third node acquisition attempt to acquire the third node.
-
-
14. The non-transitory computer readable storage medium of claim 12, the instructions further comprising functionality to:
-
release the lock; and free the first node, wherein, upon the releasing of the lock, the first node is eligible for acquisition by one of the plurality of threads.
-
-
15. The non-transitory computer readable storage medium of claim 12, the instructions further comprising functionality to:
-
determine whether a first time period specified to acquire the lock has elapsed, upon failure of the first node insertion attempt; when the first time period has elapsed; abort any further node insertion attempts; free the first node; and when the first time period has not elapsed; make a second node insertion attempt to insert the first node into the wait queue.
-
Specification