diff --git a/ChangeLog b/ChangeLog index a0ec66fc21..1cbedd5ce3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Sep 23 22:58:57 2009 Tanaka Akira + + * lib/thread.rb (ConditionVariable#wait): add timeout argument. + [ruby-talk:346154] + Wed Sep 23 21:25:20 2009 Nobuyoshi Nakada * ext/bigdecimal/lib/bigdecimal/math.rb (atan): refined. diff --git a/NEWS b/NEWS index a384402980..3adf36ec6e 100644 --- a/NEWS +++ b/NEWS @@ -230,6 +230,10 @@ with all sufficient information, see the ChangeLog file. * incompatible changes: * Time.parse raises ArgumentError when no date information. +* thread + * extended method: + * ConditionVariable#wait takes timeout argument. + * securerandom * new methods: * SecureRandom.urlsafe_base64 diff --git a/lib/thread.rb b/lib/thread.rb index cb6d8c62fc..34c2a506d2 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -59,13 +59,16 @@ class ConditionVariable # # 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