1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/timeout] Synchronize all accesses to @done

* So it is trivially correct.
* Performance seems the same overall.

5e0d8e1637
This commit is contained in:
Benoit Daloze 2022-05-15 13:49:31 +02:00 committed by git
parent 354cd6f210
commit 240ac9eaa8

View file

@ -67,12 +67,14 @@ module Timeout
@message = message @message = message
@mutex = Mutex.new @mutex = Mutex.new
@done = false @done = false # protected by @mutex
end end
def done? def done?
@mutex.synchronize do
@done @done
end end
end
def expired?(now) def expired?(now)
now >= @deadline and !done? now >= @deadline and !done?