×

Reader-writer lock

  • US 9,329,895 B2
  • Filed: 01/22/2014
  • Issued: 05/03/2016
  • Est. Priority Date: 01/22/2014
  • Status: Active Grant
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.

View all claims
  • 1 Assignment
Timeline View
Assignment View
    ×
    ×