From: Robert Klemme Date: 2004-10-29T16:38:57+09:00 Subject: Re: Thread::list and GC "Bill Kelly" schrieb im Newsbeitrag news:003b01c4bd78$530e7c80$6442a8c0@musicbox... > From: "Ara.T.Howard" > > > > are there any issues with iterating Thread::list - since this list is > > obviously changing all the time in this code (new Threads started) > > Maybe, > > while th = Thread::list.find {|t| t != Thread.current} > begin > th.join > rescue => e > warn{ e } > end > end This does not make a difference as Thread.list() creates a new array on each invokation: >> Thread.list().id => 135026036 >> Thread.list().id => 135022100 >> Thread.list().id => 135018212 So you can safely walk through the array as long as you like. Threads are GC'ed after termination: 09:32:51 [ruby]: ./th-list.rb [#] .. [#, #] [#] [#] 09:32:55 [ruby]: cat th-list.rb #!/usr/bin/ruby p Thread.list Thread.new do puts "." sleep 1 end p Thread.list sleep 1 p Thread.list GC.start p Thread.list 09:32:57 [ruby]: The std lib contains a class that helps with the termination of multiple threads: http://www.ruby-doc.org/stdlib/libdoc/thwait/rdoc/index.html Kind regards robert