Project

General

Profile

Bug #16608

ConditionVariable#wait should return false when timeout exceeded

Added by shugo (Shugo Maeda) 8 months ago. Updated 4 months ago.

Status:
Assigned
Priority:
Normal
Target version:
-
[ruby-core:97063]

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.

Updated by shugo (Shugo Maeda) 8 months ago

  • Assignee set to shugo (Shugo Maeda)
  • Status changed from Open to Assigned

Updated by shugo (Shugo Maeda) 8 months ago

  • Assignee changed from shugo (Shugo Maeda) to nobu (Nobuyoshi Nakada)

nobu (Nobuyoshi Nakada) wrote in #note-2:

How about https://github.com/ruby/ruby/pull/2884

ko1 suggested Mutex#release (new version of Mutex#sleep) for backward compatibility.
What do you think of it?

Updated by Eregon (Benoit Daloze) 8 months ago

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.

Updated by jeremyevans0 (Jeremy Evans) 4 months ago

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!.

Also available in: Atom PDF