[erlang-questions] Unexpected behaviour of timer:sleep

Bjorn Gustavsson bjorn@REDACTED
Wed Mar 19 15:47:44 CET 2008


"James Hague" <james.hague@REDACTED> writes:

> On Wed, Mar 19, 2008 at 8:14 AM, Bengt Kleberg
> <bengt.kleberg@REDACTED> wrote:
> >
> >  Have you tested
> >
> >  receive
> >  after 1 -> ok
> >  end.
> >
> >  It might be more accurate.
> 
> Not under OS X it isn't.  I started a thread about this last year:
> there's no way to sleep with a granularity of less than 10-15
> milliseconds.  The group discussion pinned this on the underlying
> operating system, which I'm not sure I buy.  Rather horribly, I
> resorted to a busy wait loop that continually calls now/0, which works
> perfectly, but sure causes the fan on my MacBook to spin up.

On Mac OS 10.4.11:

1> timer:tc(timer, sleep, [1]).
{10085,ok}

On Mac OS 10.5.2:

1> timer:tc(timer, sleep, [1]).
{1295,ok}

I remember reading somewhere in Apple's documentation that select() had
a minimum sleeping time of 10 ms in Tiger, but it was changed in Leopard.

/Bjorn
-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list