[MacRuby] #572: ConditionVariable#wait should accept a timeout argument

MacRuby ruby-noreply at macosforge.org
Sat Dec 4 18:43:01 PST 2010


#572: ConditionVariable#wait should accept a timeout argument
---------------------------------+------------------------------------------
 Reporter:  honglilai@…          |       Owner:  lsansonetti@…        
     Type:  defect               |      Status:  new                  
 Priority:  blocker              |   Milestone:                       
Component:  MacRuby              |    Keywords:                       
---------------------------------+------------------------------------------

Comment(by isaackearse@…):

 Looks like ruby-core have rejected this change a month ago.  Below are the
 reasons given, for more info see the thread on rubymine: http://redmine
 .ruby-lang.org/issues/show/2629

 Hi, Hongli

 Even if there is no return value, you can detect the timeout
 *without guessing* by the following:


 {{{
   mutex.synchronize do
     t = Time.now + x
     until @quit
       t2 = Time.now
       cv.wait(mutex, t - t2) if t > t2
       break if @quit
       if Time.now > t
         t += x
         # cleanup code
       end
     end
     # stop the loop
   end

 }}}

 I recommend this code because it is robust against spurious
 wakeup.


 I think the feature you requested can be used to make the
 code more efficient, like the following:


 {{{
   mutex.synchronize do
     t = Time.now + x
     until @quit
       t2 = Time.now
       timeout = t <= t2 || cv.wait(mutex, t - t2)
       break if @quit  # (A)
       if timeout
         t += x
         # cleanup code
       end
     end
     # stop the loop
   end

 }}}

 But, the feature is not mandatory, and is even prone to misuse
 (the check (A) is very easy to forget).

 In addition, Tanaka Akira, who has added the timeout feature
 to CV#wait, rejected the feature.

 Consequently, I close this ticket.  Sorry for decision against
 your exception, and also sorry for not deciding sooner.

 --
 Yusuke Endoh <mame at tsg.ne.jp>

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/572#comment:3>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list