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

Rickard Green rickard@REDACTED
Tue Feb 23 15:58:16 CET 2016


Missed reply all...

-------- Forwarded Message --------
Subject: Re: [erlang-questions] Sending message at a specific and 
accurate time
Date: Tue, 23 Feb 2016 15:55:19 +0100
From: Rickard Green <rickard@REDACTED>
Organization: Ericsson AB
To: Tony Rogvall <tony@REDACTED>

On 02/23/2016 02:29 PM, Tony Rogvall wrote:
>
>> On 22 feb 2016, at 15:55, Joe Armstrong <erlang@REDACTED> wrote:
>>
>> On Mon, Feb 22, 2016 at 3:31 PM, Tony Rogvall <tony@REDACTED> wrote:
>>>> L = fun Loop() -> receive after 1 ->  Loop()  end end.
>>>> spawn_link(L).
>>
>> Busy sleep :-) < I thought busy waiting was frowned upon>
>>
>> Actually after 10 works as well.
>>
>
> When running a busy sleep loop of 1 ms I get a 990 us diff from the actual time
> and when running a busy loop of 10 ms I get 1550 us diff.
> BTW The same is true for smp disable
>
> Question for Richard really is why ? :-)

The accuracy of the timeout delivered by the underlying primitive used
(select() on macosx). It seems that the accuracy is better for short
timeouts than long timeouts using select() on macosx.

Using the above approach you also need a bit of luck in the smp case.
The looping process needs to execute on the same scheduler thread as the
scheduler thread managing the timer you want to improve.

Regards,
Rickard






More information about the erlang-questions mailing list