From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: * X-Spam-ASN: AS33070 50.56.128.0/17 X-Spam-Status: No, score=1.0 required=3.0 tests=AWL,HK_RANDOM_FROM, MSGID_FROM_MTA_HEADER,TVD_RCVD_IP shortcircuit=no autolearn=no version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.rainbows.general Subject: Re: negative timeout in Rainbows::Fiber::Base Date: Sat, 25 Aug 2012 02:45:56 +0000 Message-ID: <20120825024556.GA25977@dcvr.yhbt.net> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1345863502 22967 80.91.229.3 (25 Aug 2012 02:58:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 25 Aug 2012 02:58:22 +0000 (UTC) Cc: "Lin Jen-Shin \(godfat\)" To: Rainbows! list Original-X-From: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Sat Aug 25 04:58:22 2012 Return-path: Envelope-to: gclrrg-rainbows-talk@m.gmane.org X-Original-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Delivered-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-BeenThere: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Errors-To: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Xref: news.gmane.org gmane.comp.lang.ruby.rainbows.general:395 Archived-At: Received: from 50-56-192-79.static.cloud-ips.com ([50.56.192.79] helo=rubyforge.org) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T56Zp-0007Rj-Uk for gclrrg-rainbows-talk@m.gmane.org; Sat, 25 Aug 2012 04:58:22 +0200 Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 1D6BE2E061; Sat, 25 Aug 2012 02:58:18 +0000 (UTC) Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 94C582E05F for ; Sat, 25 Aug 2012 02:45:57 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id A6A0C335BC; Sat, 25 Aug 2012 02:45:56 +0000 (UTC) "Lin Jen-Shin (godfat)" wrote: > Greetings Unicorns, > > I am writing some stupid benchmarks, trying FiberSpawn and > FiberPool, and seeing this error: > > listen loop error: time interval must be positive (ArgumentError) > > Looking into the code, in this line: > http://bogomips.org/rainbows.git/tree/lib/rainbows/fiber/base.rb#n55 > Isn't that possible `max <= (now + 1)` and `now > max`? > Whenever this is the case, then timeout passed to `select` > could be negative. I am not sure how to fix this correctly, > but a blind `abs` could resolve this error. The original code looks wrong and confusing :x It's been a while since I've looked hard at the Fiber* stuff (not a fan of it personally). However, I don't think abs() is correct, either. > Hope this could give some hints, thank you! Perhaps this is less confusing and more correct: diff --git a/lib/rainbows/fiber/base.rb b/lib/rainbows/fiber/base.rb index 6828e1d..103c97a 100644 --- a/lib/rainbows/fiber/base.rb +++ b/lib/rainbows/fiber/base.rb @@ -51,12 +51,15 @@ module Rainbows::Fiber::Base end } fibs.each { |fib| fib.resume } - now = Time.now + + max_sleep = 1.0 if max - timeout = max - now - timeout < 0.0 ? 0 : timeout + max -= Time.now + return 0 if max < 0.0 + return max_sleep if max > max_sleep + max else - 1 + max_sleep end end --- Thoughts? _______________________________________________ Rainbows! mailing list - rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org http://rubyforge.org/mailman/listinfo/rainbows-talk Do not quote signatures (like this one) or top post when replying