Re: [9fans] fossil periodic thread does zero sleep()
- From: rminnich@xxxxxxxxx (ron minnich)
- Date: Mon, 23 Mar 2009 13:32:11 GMT
Sigh ... Do not send mail when tired. Was thinking of different problem.
Ron
On 3/22/09, ron minnich <rminnich@xxxxxxxxx> wrote:
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@xxxxxx <cinap_lenrek@xxxxxx> 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
--
Sent from my mobile device
.
- References:
- Re: [9fans] fossil periodic thread does zero sleep()
- From: ron minnich
- Re: [9fans] fossil periodic thread does zero sleep()
- Prev by Date: Re: I can not remember if I sent this or not: MIPS-64 (sort of) notebook
- Next by Date: Re: [9fans] looking for opinions on Interprocess communication
- Previous by thread: Re: [9fans] fossil periodic thread does zero sleep()
- Next by thread: Re: [9fans] fossil periodic thread does zero sleep()
- Index(es):
Relevant Pages
|