diff options
| author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-04-02 05:27:49 +0000 |
|---|---|---|
| committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-04-02 05:27:49 +0000 |
| commit | 2a0b56728c184fdd72512ba790ed5d5796dd5ae1 (patch) | |
| tree | 00ec4ee4ed228ad99b923568d2ec1f0985913300 /lib | |
| parent | 81e556623817bcfff960b9f75adbad7e706c7d19 (diff) | |
| download | ruby-2a0b56728c184fdd72512ba790ed5d5796dd5ae1.tar.gz ruby-2a0b56728c184fdd72512ba790ed5d5796dd5ae1.tar.xz ruby-2a0b56728c184fdd72512ba790ed5d5796dd5ae1.zip | |
* lib/monitor.rb (wait): fix timeout support.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@1302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/monitor.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/monitor.rb b/lib/monitor.rb index d36546ab6..721c51a9f 100644 --- a/lib/monitor.rb +++ b/lib/monitor.rb @@ -69,6 +69,15 @@ module MonitorMixin raise ThreadError, "current thread not owner" end + if timeout + ct = Thread.current + timeout_thread = Thread.start { + Thread.pass + sleep(timeout) + ct.raise(Timeout.new) + } + end + Thread.critical = true count = @monitor.mon_count @monitor.mon_count = 0 @@ -80,23 +89,18 @@ module MonitorMixin end t.wakeup if t @waiters.push(Thread.current) - - if timeout - t = Thread.current - timeout_thread = Thread.start { - sleep(timeout) - t.raise(Timeout.new) - } - end + begin Thread.stop rescue Timeout - @waiters.delete(Thread.current) ensure Thread.critical = true if timeout && timeout_thread.alive? Thread.kill(timeout_thread) end + if @waiters.include?(Thread.current) # interrupted? + @waiters.delete(Thread.current) + end while @monitor.mon_owner && @monitor.mon_owner != Thread.current @monitor.mon_waiting_queue.push(Thread.current) |
