Skip to content

Commit 0d55fa3

Browse files
committed
If write lock is not held do not change the counter
lead to inconsistent lock state
1 parent 0f49c5e commit 0d55fa3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/concurrent/atomic/read_write_lock.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ def acquire_write_lock
193193
#
194194
# @return [Boolean] true if the lock is successfully released
195195
def release_write_lock
196-
c = @Counter.update { |counter| counter-RUNNING_WRITER }
196+
return true unless running_writer?
197+
c = @Counter.update { |counter| counter - RUNNING_WRITER }
197198
@ReadLock.broadcast
198199
@WriteLock.signal if waiting_writers(c) > 0
199200
true

0 commit comments

Comments
 (0)