caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Thread.delay, Unix.select, Unix.gettimeofday, Sys.time together?
@ 2003-06-07 12:17 Nick Name
  2003-06-07 13:31 ` Nicolas George
  2003-06-09 16:19 ` Xavier Leroy
  0 siblings, 2 replies; 3+ messages in thread
From: Nick Name @ 2003-06-07 12:17 UTC (permalink / raw)
  To: caml-list

Hi all,

I have a cycle similar to the following in my program:

while true do 
	Thread.delay mydelay; 
	print_float Unix.gettimeofday (); 
	print_newline()
done

If I put the delay into the cycle, I can't get less than 1/100 of second
delay, on any machine I do this test. Is there a portable function that
can do a shorter delay, say 1/1000 of second ad least?

BTW, I have found a problem in using Sys.time and Thread.delay together:
if I DON'T use Thread.delay, Sys.time returns an increasing value, as
it's expected to. If I do a cycle like

while true do 
	Thread.delay mydelay; 
	print_float Sys.time (); 
	print_newline()
done

Sys.time returns an almost constant value! This also happens if I use
Unix.select [] [] [] mydelay instead of Thread.delay. I suspect this
happens because some sort of counter gets reset by a delay, but this
makes no sense.

If this might be a bug I'll do the bug report.

thanks for attention

Vincenzo

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Thread.delay, Unix.select, Unix.gettimeofday, Sys.time together?
  2003-06-07 12:17 [Caml-list] Thread.delay, Unix.select, Unix.gettimeofday, Sys.time together? Nick Name
@ 2003-06-07 13:31 ` Nicolas George
  2003-06-09 16:19 ` Xavier Leroy
  1 sibling, 0 replies; 3+ messages in thread
From: Nicolas George @ 2003-06-07 13:31 UTC (permalink / raw)
  To: caml-list; +Cc: Nick Name

[-- Attachment #1: Type: text/plain, Size: 1092 bytes --]

Le nonidi 19 prairial, an CCXI, Nick Name a écrit :
> If I put the delay into the cycle, I can't get less than 1/100 of second
> delay, on any machine I do this test.

I guess you didn't try with Linux/alpha :) The 1/100 of second is the
time slice of the scheduler of the OS. Anything that sleeps by calling
the OS will sleep at least that.

>					Is there a portable function that
> can do a shorter delay, say 1/1000 of second ad least?

You need to do busy wait: keep running and check the clock until the
delay is over. Please note that busy wait is considered evil.

> Sys.time returns an almost constant value! This also happens if I use
> Unix.select [] [] [] mydelay instead of Thread.delay. I suspect this
> happens because some sort of counter gets reset by a delay, but this
> makes no sense.

The answer is in the manual: Sys.time returns the processor time of your
program. While sleeping, your program does not burn CPU, so Sys.time
does not grow. It will only grow during the phases between the sleeps,
and this will be much slower than whithout sleep.

[-- Attachment #2: Type: application/pgp-signature, Size: 185 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] Thread.delay, Unix.select, Unix.gettimeofday, Sys.time together?
  2003-06-07 12:17 [Caml-list] Thread.delay, Unix.select, Unix.gettimeofday, Sys.time together? Nick Name
  2003-06-07 13:31 ` Nicolas George
@ 2003-06-09 16:19 ` Xavier Leroy
  1 sibling, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2003-06-09 16:19 UTC (permalink / raw)
  To: Nick Name; +Cc: caml-list

> If I put the delay into the cycle, I can't get less than 1/100 of second
> delay, on any machine I do this test. Is there a portable function that
> can do a shorter delay, say 1/1000 of second ad least?

Not in a portable way, I'm afraid.  Most Unix kernels round delays up
to the next clock tick, and use clocks of 50, 60 or 100 Hz.
Linux/Alpha is an exception, with a 1000 Hz (or 1024?) clock.

Under Linux, you could use Unix.select() on /dev/rtc.  This device can be
programmed to generate ticks with a frequency between 1 Hz and 8192 Hz
in powers of 2.  Check Documentation/rtc.txt in the Linux source tree
for more details.

- Xavier Leroy

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-06-09 16:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-07 12:17 [Caml-list] Thread.delay, Unix.select, Unix.gettimeofday, Sys.time together? Nick Name
2003-06-07 13:31 ` Nicolas George
2003-06-09 16:19 ` Xavier Leroy

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).