Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Thread.delay,, Unix.gettimeofday, Sys.time together?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Nicolas George <>
Subject: Re: [Caml-list] Thread.delay,, Unix.gettimeofday, Sys.time together?
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
> [] [] [] 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.