发明名称 READER-WRITER LOCK
摘要 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.
申请公布号 US2015205733(A1) 申请公布日期 2015.07.23
申请号 US201414160675 申请日期 2014.01.22
申请人 International Business Machines Corporation 发明人 Steinmacher-Burow Burkhard
分类号 G06F12/14 主分类号 G06F12/14
代理机构 代理人
主权项 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; anda 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.
地址 Armonk NY US