[erlang-questions] Sending message at a specific and accurate time

Rickard Green <>
Mon Feb 22 16:55:57 CET 2016


> I can only conclude that send_after(Time, Pid, Msg) is deeply broken on the
> mac - if inter-processing scheduling and messaging had 6 millisecond
> delays Erlang would be unusable.
>

When schedulers run out of work they eventually need to sleep. A
timeout is set up in order to service next timeout. On macosx we will
sleep in select(). The timeout is set on microsecond level, but on
macosx the thread is often woken milliseconds after the time we
requested. When the thread wakeup is delayed like this, timers handled
by the thread will also be delayed. I verified the delayed timeout in
select() using a simple c-program, and the figures corresponds to what
can be seen in your send_after() test. That is, it is not the timer
implementation in the vm that delays the timers.

> I guess I could do a send_after 10ms before I want and then do a busy wait
> but this would be crazy.
>

If the primitive used for waiting has this kind of delay, a busy wait
is more or less what is left. The vm could of course perform this busy
wait for you, but my guess is that this busy wait wouldn't be received
well by the users. It is however an option.

Regards,
Rickard
-- 
Rickard Green, Erlang/OTP, Ericsson AB


More information about the erlang-questions mailing list