diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-11 01:20:45 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-10-11 01:20:45 +0000 |
commit | 764722dc2737f7ee2686c1012539d1c5bd6446b8 (patch) | |
tree | 9d098d479bec57e5b586fecc270fb8f8485eef5b /lib/monitor.rb | |
parent | 45b46d78fa09c085089a9e4ea17fde522ea1f0ef (diff) | |
download | ruby-764722dc2737f7ee2686c1012539d1c5bd6446b8.tar.gz |
* lib/monitor.rb: handle exceptions correctly. Thanks, Gennady
Bystritsky.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4740 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/monitor.rb')
-rw-r--r-- | lib/monitor.rb | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/lib/monitor.rb b/lib/monitor.rb index 5eb7bb4e03..c7f610cef6 100644 --- a/lib/monitor.rb +++ b/lib/monitor.rb @@ -130,10 +130,14 @@ module MonitorMixin t.wakeup if t @waiters.push(Thread.current) - begin - Thread.stop - rescue Timeout - ensure + preserved_exceptions = [] + while true + begin + Thread.stop + rescue Timeout + rescue Exception => exception + preserved_exceptions << exception + end Thread.critical = true if timeout && timeout_thread.alive? Thread.kill(timeout_thread) @@ -141,15 +145,17 @@ module MonitorMixin 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) - Thread.stop - Thread.critical = true - end - @monitor.mon_owner = Thread.current - @monitor.mon_count = count - Thread.critical = false + + break if @monitor.mon_owner.nil? or @monitor.mon_owner == Thread.current + @monitor.mon_waiting_queue.delete(Thread.current) + @monitor.mon_waiting_queue.push(Thread.current) + end + @monitor.mon_owner = Thread.current + @monitor.mon_count = count + Thread.critical = false + + unless preserved_exceptions.empty? + raise preserved_exceptions.first end end @@ -232,6 +238,7 @@ module MonitorMixin def mon_enter Thread.critical = true while mon_owner != nil && mon_owner != Thread.current + mon_entering_queue.delete(Thread.current) mon_entering_queue.push(Thread.current) Thread.stop Thread.critical = true |