Need some thread help

M

Mike Wilson

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.

<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()
</code>

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/
 
T

ts

M> threads = []
M> check_status = proc {
M> $labels.each_key do |aHost|
M> threads << Thread.new(aHost) do |host|
[...]
M> Now, the "threads.each do |t| t.join end" currently doesn't work (probably
M> obvious). I know this because the memory stack size increases with every
M> 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,371
Latest member
TroyHursey

Latest Threads

Top