READER-WRITER LOCK
First Claim
Patent Images
1. A method for implementing a reader-writer lock having a write lock requested by a thread, the method comprising:
- structuring the reader-writer lock to have;
a first counter configured to count, using an atomic process to increment the first counter in response to a first bit of the first counter being enabled, a number of read locks held, wherein the first bit is initially set to be enabled;
a second counter configured to count, using the atomic process to increment the second counter in response to a second bit of the second counter being enabled, a number of outstanding read lock requests, wherein the second bit is initially set to be disabled; and
a flag, identifying either the first counter or the second counter but not both, configured to discern the first counter from the second counter, wherein the flag is initially set to identify the first counter;
preparing, using the atomic process in association with at least one counter of the first and second counters, a read lock associated with a flagged counter of the first and second counters;
acquiring, by polling the flag to identify the flagged counter of the first and second counters, the read lock;
releasing, using the flagged counter to decrement a value of the flagged counter, the read lock;
preparing, by disabling the flagged counter and enabling an unflagged counter of the first and second counters, a write lock;
acquiring, by polling the flagged counter until the value of the flagged counter reaches zero, the write lock; and
releasing, using the flag to unflag the flagged counter and flag the unflagged counter, the write lock.
1 Assignment
0 Petitions
Accused Products
Abstract
A method and system for implementing a reader-writer lock having a write lock requested by a thread is disclosed. The reader-writer lock is structured to have counters and a flag. The counters use an atomic process to count read locks held or outstanding read lock requests. The flag identifies a counter and is configured to distinguish between counters. A read lock is prepared, acquired, and released. The atomic process is used and the flag or flagged counter is polled. A write lock is prepared, acquired, and released.
10 Citations
20 Claims
-
1. A method for implementing a reader-writer lock having a write lock requested by a thread, the method comprising:
-
structuring the reader-writer lock to have; a first counter configured to count, using an atomic process to increment the first counter in response to a first bit of the first counter being enabled, a number of read locks held, wherein the first bit is initially set to be enabled; a second counter configured to count, using the atomic process to increment the second counter in response to a second bit of the second counter being enabled, a number of outstanding read lock requests, wherein the second bit is initially set to be disabled; and a flag, identifying either the first counter or the second counter but not both, configured to discern the first counter from the second counter, wherein the flag is initially set to identify the first counter; preparing, using the atomic process in association with at least one counter of the first and second counters, a read lock associated with a flagged counter of the first and second counters; acquiring, by polling the flag to identify the flagged counter of the first and second counters, the read lock; releasing, using the flagged counter to decrement a value of the flagged counter, the read lock; preparing, by disabling the flagged counter and enabling an unflagged counter of the first and second counters, a write lock; acquiring, by polling the flagged counter until the value of the flagged counter reaches zero, the write lock; and releasing, using the flag to unflag the flagged counter and flag the unflagged counter, the write lock. - View Dependent Claims (2, 3, 4, 5, 6, 7, 8)
-
-
9. A computer-implemented method for processing a set of access requests of a resource shared by a set of threads, the method comprising:
-
creating a set of pools for storing the set of access requests of the resource, the set of pools including a first pool configured to be active and a second pool configured to be inactive; processing a first request of a first type of the set of access requests of the first pool; and switching, in response to processing a second request of a second type of the set of access requests of the first pool, the first pool to be the second pool configured to be inactive and the second pool to be the first pool configured to be active. - View Dependent Claims (10, 11, 12, 13, 14, 15, 16)
-
-
17. A system processing a set of access requests of a resource shared by a set of threads, the system comprising:
a reader-writer lock configured to; provide a set of pools for storing data access requests; assign a first pool of the set of pools to a first pool position; assign a second pool of the set of pools to a second pool position; wait for data access requests to access data by performing the following steps; storing received read requests to the pool in the first position until a write request acquires a first ticket of a ticket lock and spins until a first turn associated with the pool in the first position, subsequently storing received read requests to the pool in the second position until a write request acquires a second ticket of the ticket lock and spins until a second turn associated with the pool in the second position, and subsequently waiting for the pool in the first position to become empty and then exchanging the first and second pool positions of the pools; and atomically process the stored data access requests in the pool in the first pool position. - View Dependent Claims (18, 19, 20)
Specification