From d838e5ef01471eb12aec42639246946f7b3da4a5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 17 Oct 2009 22:42:55 -0700 Subject: use timeout correctly to join threads on SIGQUIT Subtraction is a difficult concept for some folks (like myself) to grasp and implement. --- lib/rainbows/base.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb index 3f9db96..a78262e 100644 --- a/lib/rainbows/base.rb +++ b/lib/rainbows/base.rb @@ -85,14 +85,13 @@ module Rainbows def join_threads(threads, worker) logger.info "Joining threads..." threads.each { |thr| thr[:quit] = true } - t0 = Time.now - timeleft = timeout * 2.0 + expire = Time.now + (timeout * 2.0) m = 0 - while (nr = threads.count { |thr| thr.alive? }) > 0 && timeleft > 0 + while (nr = threads.count { |thr| thr.alive? }) > 0 threads.each { |thr| worker.tmp.chmod(m = 0 == m ? 1 : 0) thr.join(1) - break if (timeleft -= (Time.now - t0)) < 0 + break if Time.now >= expire } end logger.info "Done joining threads. #{nr} left running" -- cgit v1.2.3-24-ge0c7