diff options
| author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-23 14:01:07 +0000 |
|---|---|---|
| committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-23 14:01:07 +0000 |
| commit | c3e13f40cfc664370f635f6be1927fabdda5f1d9 (patch) | |
| tree | 0d47649ecfe6ecf13fa1397b739f5cca9efbf130 | |
| parent | e6f7edacea92b39e118a9a82ed7a83b2b428a52b (diff) | |
| download | ruby-c3e13f40cfc664370f635f6be1927fabdda5f1d9.tar.gz ruby-c3e13f40cfc664370f635f6be1927fabdda5f1d9.tar.xz ruby-c3e13f40cfc664370f635f6be1927fabdda5f1d9.zip | |
* lib/thread.rb (ConditionVariable#wait): add timeout argument.
[ruby-talk:346154]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@25058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 5 | ||||
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | lib/thread.rb | 7 |
3 files changed, 14 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Wed Sep 23 22:58:57 2009 Tanaka Akira <akr@fsij.org> + + * lib/thread.rb (ConditionVariable#wait): add timeout argument. + [ruby-talk:346154] + Wed Sep 23 21:25:20 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> * ext/bigdecimal/lib/bigdecimal/math.rb (atan): refined. @@ -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 cb6d8c62f..34c2a506d 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 |
