lib/rainbows/thread_pool.rb in rainbows-0.94.0 vs lib/rainbows/thread_pool.rb in rainbows-0.95.0

- old
+ new

@@ -23,11 +23,11 @@ module ThreadPool include Base - def worker_loop(worker) + def worker_loop(worker) # :nodoc: init_worker_process(worker) pool = (1..worker_connections).map do Thread.new { LISTENERS.size == 1 ? sync_worker : async_worker } end @@ -39,39 +39,44 @@ end end join_threads(pool) end - def sync_worker - s = LISTENERS.first + def sync_worker # :nodoc: + s = LISTENERS[0] begin c = Rainbows.sync_accept(s) and process_client(c) rescue => e Error.listen_loop(e) end while G.alive end - def async_worker + def async_worker # :nodoc: begin # TODO: check if select() or accept() is a problem on large # SMP systems under Ruby 1.9. Hundreds of native threads # all working off the same socket could be a thundering herd # problem. On the other hand, a thundering herd may not # even incur as much overhead as an extra Mutex#synchronize - ret = IO.select(LISTENERS, nil, nil, 1) and ret.first.each do |s| + ret = IO.select(LISTENERS, nil, nil, 1) and ret[0].each do |s| s = Rainbows.accept(s) and process_client(s) end rescue Errno::EINTR rescue => e Error.listen_loop(e) end while G.alive end - def join_threads(threads) + def join_threads(threads) # :nodoc: G.quit! threads.delete_if do |thr| G.tick - thr.alive? ? thr.join(0.01) : true + begin + thr.run + thr.join(0.01) + rescue + true + end end until threads.empty? end end end