Re: [9fans] fossil periodic thread does zero sleep()



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

.



Relevant Pages

  • Re: sort of poker question
    ... Although we are aware of an increasing demand for a mobile device version of ... It is theoretically possible to play using a device like the Apple iPad, ... connectivity issues involved, and we cannot provide support for such play. ...
    (rec.gambling.poker)
  • Re: Sucks to be good... Paid files dont transfer to ipaq
    ... to the Pocket PC's main memory it will work. ... > file into mobile device using explorer it does transfer - but it says ... > on your pc to copy the file to your device again" when I try to play ... > JUST FINE on my ipaq... ...
    (microsoft.public.pocketpc)
  • Re: [9fans] fossil periodic thread does zero sleep()
    ... to play a with the code to see how it reacts to some changes. ... and how to fix it :-) ...
    (comp.os.plan9)
  • Re: Need to calculate milleseconds until 1:00am...
    ... static void Main ... in milliseconds. ... 1:00am for my countdown timer please. ... need the calculation for 'after 1:00' to get it reset for the next ...
    (microsoft.public.dotnet.languages.csharp)
  • [9fans] SB600 i/o error on read/write
    ... looks like we hit this: ... is ms in TK2MS refering to milliseconds? ...
    (comp.os.plan9)