nicer thread startup/breakdown

This commit is contained in:
Ward Wouts 2005-03-01 19:56:56 +00:00
parent 429d66c9b1
commit 02f5b7886f

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/ruby -w
# $Dwarf: ripnews.rb,v 1.101 2005/02/06 13:43:52 ward Exp $
# $Dwarf: ripnews.rb,v 1.102 2005/03/01 09:18:50 ward Exp $
# $Source$
#
@ -27,6 +27,7 @@ require 'news/article'
require 'news/newsrc'
require 'tempfile'
require 'thread'
require 'thwait'
require 'encode/uuencode'
require 'encode/yenc'
@ -427,9 +428,9 @@ def get_multi(subj, group)
end
@decode_threads << Thread.new(body, file, fileout, subj) do |tbody, tfile, tfileout, tsubj|
# imediately stop to continue with main program
Thread.stop
puts "inside thread\n"
puts "inside thread pre pass\n"
Thread.pass
puts "inside thread post pass\n"
if UUEncode.is_uuencoded(tbody)
print " UUDecoding...\n"
if tfile
@ -477,25 +478,6 @@ def get_multi(subj, group)
output_data(tsubj, tmode, tfilename, tbody)
end # thread end
# (0 ... @decode_threads.length).to_a.reverse.each{ |x|
# if @decode_threads[x].status == "sleep"
# @decode_threads[x].run
# elsif @decode_threads[x].status == "false" && @decode_threads[x].join
# @decode_threads.delete_at(x)
# end
# }
Thread.list.each {|t| p t}
@decode_threads.each{ |thr|
if thr.status == "sleep" # and fire up the threads again
thr.run
elsif thr.status == "false" # remove finished threads
thr.join
# else
## p thr.status
end
}
Thread.list.each {|t| p t}
puts "ouside thread\n"
return true
@ -703,20 +685,9 @@ def main
if ! @decode_threads.empty?
@articles.disconnect
puts "Waiting for decode threads..."
# while @decode_threads
# (0 ... @decode_threads.length).to_a.reverse.each{ |x|
# if @decode_threads[x].status == "false" && @decode_threads[x].join(0.15)
# puts "deleting #{x} from thread pool"
# @decode_threads.delete_at(x)
# end
# }
# end
Thread.list.each {|t| p t}
@decode_threads.each{|thr|
p "thr inspect #{thr.inspect}"
thr.join
ThreadsWait.all_waits(@decode_threads){ |t|
p "Thread #{t} has terminated"
}
Thread.list.each {|t| p t}
puts "Decode threads all done"
end