From: Tanaka Akira Date: 2009-09-11T00:16:23+09:00 Subject: Re: Timer implementation In article <4aa8deb2$0$25181$d40e179e@nntp02.dk.telia.net>, Robert Larsen writes: > BUT...the 'start' method does not work since 'ConditionVariable' does not have a 'wait' method that takes a maximum wait time in milliseconds like we have in Java. In ruby 1.9, timeout argument can be implemented as follows. Index: lib/thread.rb =================================================================== --- lib/thread.rb (revision 24783) +++ lib/thread.rb (working copy) @@ -59,13 +59,16 @@ # # Releases the lock held in +mutex+ and waits; reacquires the lock on wakeup. # - def wait(mutex) + # If +timeout+ is given, this method returns after +timeout+ seconds passed, + # even if no other thread doesn't signal. + # + def wait(mutex, timeout=nil) begin # TODO: mutex should not be used @waiters_mutex.synchronize do @waiters.push(Thread.current) end - mutex.sleep + mutex.sleep timeout end end -- Tanaka Akira