summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-23 14:01:07 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-23 14:01:07 +0000
commit7728a17a27f9b9eeac9bc2ec04e54dd6fd3b3160 (patch)
tree0d47649ecfe6ecf13fa1397b739f5cca9efbf130 /lib
parent8c3926aea0d782d28fc42ca8d391ce7ec9533e31 (diff)
* lib/thread.rb (ConditionVariable#wait): add timeout argument.
[ruby-talk:346154] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/thread.rb7
1 files changed, 5 insertions, 2 deletions
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