From: ron minnich <rminnich@gmail.com>
To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net>
Subject: Re: [9fans] fossil periodic thread does zero sleep()
Date: Sun, 22 Mar 2009 21:04:54 -0700 [thread overview]
Message-ID: <13426df10903222104m424280d7ub9503f035eb708cb@mail.gmail.com> (raw)
In-Reply-To: <99a6e3a7cd4a1a6da9d06b97ddff4e37@gmx.de>
This is from mobile so I can not look at code much but if you are
converting nanoseconds to milliseconds you multiply by 1e6 not 1e-6 I
think.
Ron
On 3/22/09, cinap_lenrek@gmx.de <cinap_lenrek@gmx.de> wrote:
> 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 <u.h>
> #include <libc.h>
>
> 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);
> }
>
--
Sent from my mobile device
next prev parent reply other threads:[~2009-03-23 4:04 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-22 23:13 cinap_lenrek
2009-03-22 23:41 ` erik quanstrom
2009-03-23 0:16 ` cinap_lenrek
2009-03-23 0:24 ` erik quanstrom
2009-03-23 0:52 ` cinap_lenrek
2009-03-23 0:54 ` erik quanstrom
2009-03-23 4:04 ` ron minnich [this message]
2009-03-23 13:27 ` ron minnich
2009-03-23 0:24 ` cinap_lenrek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=13426df10903222104m424280d7ub9503f035eb708cb@mail.gmail.com \
--to=rminnich@gmail.com \
--cc=9fans@9fans.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).