From: Robert Klemme Date: 2010-07-29T16:15:09+09:00 Subject: Re: Problem with concurrency On 07/29/2010 07:55 AM, Tasos Laskos wrote: > Hi guys, > > I'm having an issue with a multi-threaded system I'm developing. > > Sorry if my question sounds too generic and unspecific but: > Are there any known pitfalls that one might come across when using > threads? > > This is the code that runs the threads: > (I'm new to this so the code is borrowed from another post from this > list.) > --------- > def run_mods( page_data, structure ) > > mod_queue = Queue.new > > @threads = ( 1..@opts[:threads] ).map { > |i| > Thread.new( mod_queue ) { > |q| > until( q == ( curr_mod = q.deq ) ) > > if( !run_module?( curr_mod , structure ) ) > print_verbose( 'Skipping ' + curr_mod.to_s + > ', nothing to audit.' ) > next > end > > print_debug( ) > print_debug( 'Thread-' + i.to_s + " " + > curr_mod.inspect ) > print_debug( ) > > print_status( curr_mod.to_s ) > > mod_new = curr_mod.new( page_data, structure ) > > mod_new.prepare if curr_mod.method_defined?( > 'prepare' ) > mod_new.run > mod_new.clean_up if curr_mod.method_defined?( > 'clean_up' ) > > while( handle_interrupt( ) ) > end > > end > } > } > > # enque the loaded mods > for mod in ls_loaded_mods > mod_queue.enq mod > end > > @threads.size.times { mod_queue.enq mod_queue } > @threads.each { |t| t.join } > > end > ----------------- > > The modules call their parent and the parent uses Net::HTTP. > Then they get the HTTP response via the parent and manipulate it in some > way. > My main problem is that from what I've gathered some HTTP calls fail > without an error. Try this at the top of your program: Thread.abort_on_exception = true Then you will probably see errors. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/