Bug #16608
closed
ConditionVariable#wait should return false when timeout exceeded
Added by shugo (Shugo Maeda) over 4 years ago.
Updated about 3 years ago.
Description
The following program prints false
on Ruby 1.8, but true
on Ruby 1.9 or later.
require "monitor"
m = Monitor.new
c = m.new_cond
m.synchronize { p c.wait(0.1) }
However, it's not critical because most programs check the condition after wait.
- Status changed from Open to Assigned
- Assignee set to shugo (Shugo Maeda)
- Assignee changed from shugo (Shugo Maeda) to nobu (Nobuyoshi Nakada)
shugo (Shugo Maeda) wrote in #note-3:
ko1 suggested Mutex#release (new version of Mutex#sleep) for backward compatibility.
release
sounds like unlock
as in acquire/release
is similar to lock/unlock
.
So I think we need a different name there.
I'm not sure about backward compatibility, but I would think it's fine to change the return value here as probably almost nothing uses it.
I agree with @Eregon (Benoit Daloze) that we can probably change the return value of ConditionVariable#wait in Ruby 3. As it always returns true currently, it's worthless and nothing should be relying on it.
I can see that changing Mutex#sleep
to start returning nil
could break things, though. I think we do need a new method. Maybe Mutex#sleep_for
or Mutex#sleep!
.
I've added a pull request that builds on @nobu's pull request, but uses a new method (Mutex#sleep_for
) instead of making backwards-incompatible changes to Mutex#sleep
: https://github.com/ruby/ruby/pull/4256
Previous dev-meeting (March), there is no objection to change the return value of Mutex#sleep
.
matz: agreed to change the return value of Mutex#sleep.
naruse: agreed to change in Ruby 3.1 because this is so detail
Congrats!
- Assignee changed from nobu (Nobuyoshi Nakada) to soutaro (Soutaro Matsumoto)
The rbs pull request has been merged. So we just need to wait for the next rbs gem release and for bundled gems to be updated, then we can merge the pull request.
- Status changed from Assigned to Closed
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0