From: Aleksi Niemela Date: 2000-09-24T05:51:14+09:00 Subject: [ruby-list:25130] Re: How to check all Thread fin ? Sakae Kobayashi: > deadlock 0x810104c: 2:0 (main) - /usr/local/lib/ruby/1.6/thread.rb:178 > /usr/local/lib/ruby/1.6/thwait.rb:103:in `pop': Thread: > deadlock (fatal) Yashi pointed me to this thread as it seems we have some interesting behaviour here. I'm not sure if this is the patch actually fixes the bug, but at least I didn't manage to get any error messages afterwards. Index: thwait.rb =================================================================== RCS file: /home/cvs/ruby/lib/thwait.rb,v retrieving revision 1.4 diff -u -r1.4 thwait.rb --- thwait.rb 2000/09/21 06:37:23 1.4 +++ thwait.rb 2000/09/23 20:44:45 @@ -44,7 +44,7 @@ Exception2MessageMapper.extend_to(binding) def_exception("ErrNoWaitingThread", "No threads for waiting.") - def_exception("ErrNoFinshedThread", "No finished threads.") + def_exception("ErrNoFinishedThread", "No finished threads.") def ThreadsWait.all_waits(*threads) tw = ThreadsWait.new(*threads) @@ -99,8 +99,9 @@ @threads.concat threads.flatten for th in threads Thread.start do - th = th.join - @wait_queue.push th + t = th + t = t.join + @wait_queue.push t end end end @@ -131,3 +132,4 @@ end ThWait = ThreadsWait + ==================== And if you wonder why the bug happens, please try this patch and run Sakae Kobayashi's example again. Tell me if you see some surprises :). Index: thwait.rb =================================================================== RCS file: /home/cvs/ruby/lib/thwait.rb,v retrieving revision 1.4 diff -u -r1.4 thwait.rb --- thwait.rb 2000/09/21 06:37:23 1.4 +++ thwait.rb 2000/09/23 20:46:32 @@ -44,7 +44,7 @@ Exception2MessageMapper.extend_to(binding) def_exception("ErrNoWaitingThread", "No threads for waiting.") - def_exception("ErrNoFinshedThread", "No finished threads.") + def_exception("ErrNoFinishedThread", "No finished threads.") def ThreadsWait.all_waits(*threads) tw = ThreadsWait.new(*threads) @@ -99,8 +99,10 @@ @threads.concat threads.flatten for th in threads Thread.start do - th = th.join - @wait_queue.push th + t = th + put "surprise" if t != th + t = t.join + @wait_queue.push t end end end @@ -131,3 +133,4 @@ end ThWait = ThreadsWait + ============= - Aleksi