Need some thread help

I’m having some trouble with this code. I can’t figure out where to do the
thread.join at. Please excuse the extremely ugly code.

....snip....

threads = []
check_status = proc {
$labels.each_key do |aHost|
threads << Thread.new(aHost) do |host|
if $look[host] == 1
if system(“ping #{host} 4 > /dev/null 2>&1”)
…snip…
else
…snip…
end
end
end
# tried to join here, but remained very sequential.
end
# tried to join here, but had a bunch of “deadlock” stuff happen.
updater.configure(‘text’ => "Last update: " +
Time.new.strftime(DATE_FORMAT + “:%S”))
Tk.after(tknm_interval, &check_status)
}
check_status.call
threads.each do |t| t.join end
Tk.mainloop()

Now, the “threads.each do |t| t.join end” currently doesn’t work (probably
obvious). I know this because the memory stack size increases with every
loop (which is what I would expect when you keep adding threads without them
ever “join"ing back), except that if I put the join just inside the
"labels.each” loop, no actual threading occurs (it acts sequentially).
Sorry for my bad code and stupidity. :O) Any help would be appreciated.

···

Watch high-quality video with fast playback at MSN Video. Free!
http://click.atdmt.com/AVE/go/onm00200365ave/direct/01/

threads =
check_status = proc {
    $labels.each_key do |aHost|
        threads << Thread.new(aHost) do |host|

[...]

Now, the "threads.each do |t| t.join end" currently doesn't work (probably
obvious). I know this because the memory stack size increases with every
loop

Thread#join work, but you never remove the object from the Array threads,
this is why the memory increase.

More you have loop, more `threads' will have object

Guy Decoux