From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <99a6e3a7cd4a1a6da9d06b97ddff4e37@gmx.de> To: 9fans@9fans.net Date: Mon, 23 Mar 2009 01:16:07 +0100 From: cinap_lenrek@gmx.de In-Reply-To: <959ad71b3d677ea98c0e6b2ef28db2dd@quanstro.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-bbvarknmvqxjiiodxkfjucwclb" Subject: Re: [9fans] fossil periodic thread does zero sleep() Topicbox-Message-UUID: c1f394f6-ead4-11e9-9d60-3106f5b1d025 This is a multi-part message in MIME format. --upas-bbvarknmvqxjiiodxkfjucwclb Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit This is actualy very interesting. Riped the parts from periodic.c to play a with the code to see how it reacts to some changes. The code below reproduces the problem: sleep()+0x7 /sys/src/libc/9syscall/sleep.s:5 periodicThread(msec=0x3e8)+0xb2 /tmp/a.c:21 ct=0x47a68e5b t=0x47e50e4d ts=0x0 main()+0x10 /tmp/a.c:32 _main+0x31 /sys/src/libc/386/main9.s:16 The zerosleeps go away if one uncomments the foo print. It also goes away if one makes the sleep one milli second longer by changing ts to ts+1. I would love if anybody gives a good explaination of this bug and how to fix it :-) #include #include static void periodicThread(int msec) { double t, ct, ts; ct = nsec()*1e-6; t = ct + msec; for(;;){ /* skip missed */ while(t <= ct) t += msec; ts = t - ct; if(ts > 1000) ts = 1000; sleep(ts); ct = nsec()*1e-6; if(t <= ct){ // print("foo!\n"); t += msec; } } } void main(int argc, char *argv[]) { periodicThread(1000); } --upas-bbvarknmvqxjiiodxkfjucwclb Content-Type: message/rfc822 Content-Disposition: inline Return-Path: <9fans-bounces+cinap_lenrek=gmx.de@9fans.net> X-Flags: 0000 Delivered-To: GMX delivery to cinap_lenrek@gmx.de Received: (qmail invoked by alias); 22 Mar 2009 23:45:26 -0000 Received: from gouda.swtch.com (EHLO gouda.swtch.com) [67.207.142.3] by mx0.gmx.net (mx021) with SMTP; 23 Mar 2009 00:45:26 +0100 Received: from localhost ([127.0.0.1] helo=gouda.swtch.com) by gouda.swtch.com with esmtp (Exim 4.67) (envelope-from <9fans-bounces@9fans.net>) id 1LlXIF-0004WF-Kt; Sun, 22 Mar 2009 23:41:27 +0000 Received: from ladd.quanstro.net ([69.55.170.73]) by gouda.swtch.com with esmtp (Exim 4.67) (envelope-from ) id 1LlXID-0004WA-Fq for 9fans@9fans.net; Sun, 22 Mar 2009 23:41:26 +0000 Message-ID: <959ad71b3d677ea98c0e6b2ef28db2dd@quanstro.net> From: erik quanstrom Date: Sun, 22 Mar 2009 19:41:24 -0400 To: 9fans@9fans.net In-Reply-To: <64ca22ab5ee16ec3a93db27d2b78fbe7@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [9fans] fossil periodic thread does zero sleep() X-BeenThere: 9fans@9fans.net X-Mailman-Version: 2.1.9 Precedence: list Reply-To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> List-Id: Fans of the OS Plan 9 from Bell Labs <9fans.9fans.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: 9fans-bounces@9fans.net Errors-To: 9fans-bounces+cinap_lenrek=gmx.de@9fans.net X-GMX-Antivirus: 0 (no virus found) X-GMX-Antispam: 0 (Mail was not recognized as spam) X-GMX-UID: ov//cXc4YW0+Mps0wmZpWGd0amthcxsS > Can anybody explain this fossil behaviour from the periodic code? what if 0 < t - ct < 1? wouldn't it be a good idea to replace the doubles with vlongs? and replace *1e-6 with /1000000? that would make 0 < t - ct < 1 impossible. - erik --upas-bbvarknmvqxjiiodxkfjucwclb--