From 02f5b7886f5fa796f34fa2a80f188c76f9c7ca11 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Tue, 1 Mar 2005 19:56:56 +0000 Subject: [PATCH] nicer thread startup/breakdown --- trunk/ripnews/ripnews.rb | 43 +++++++--------------------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/trunk/ripnews/ripnews.rb b/trunk/ripnews/ripnews.rb index ea6723c..cb9142a 100755 --- a/trunk/ripnews/ripnews.rb +++ b/trunk/ripnews/ripnews.rb @@ -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