From: Daniel Sheppard Date: 2006-02-16T08:39:59+09:00 Subject: Re: Thread#stop The following probably contains world-destroying race-conditions, but it roughly works. Making it work properly is left as an exercise for the reader. $stoppable = [] $stop_all = false def stop_all $stop_all = true end def start_all $stop_all = false $stoppable.each {|t| p "waking #{t}"; t.wakeup} end set_trace_func proc { |event, file, line, id, binding, classname| if $stop_all && $stoppable.include?(Thread.current) p "#{Thread.current} stopping" Thread.stop p "#{Thread.current} restarted" end } $stoppable << Thread.new { while sleep 1 p "child is running" end } p "started" sleep 5 p "stopping all" stop_all sleep 5 p "starting all" start_all sleep 5 p "exiting"