ruby-concurrency / concurrent-ruby

Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.
https://ruby-concurrency.github.io/concurrent-ruby/
Other
5.68k stars 418 forks source link

can get write lock after read locked more than once only by myself #919

Closed turnon closed 3 years ago

turnon commented 3 years ago

The condition @Count == @HeldCount does not correctly indicate that WE ARE THE ONLY READER.

Because when we lock for read more than once, @HeldCount increases but @Count dosen't.

lock.with_read_lock do
  lock.with_read_lock do
    # blocked here, can not acquire write lock ! Even though no else reader
    lock.with_write_lock {}
  end
end

So we just compare @Count == 1 and try to set RUNNING_WRITER bit on

chrisseaton commented 3 years ago

Can you please rebase?

turnon commented 3 years ago

Can you please rebase?

Ok, just rebased