[erlang-questions] Erlang Scheduler for Recurring Events

Ladislav Lenart lenartlad@REDACTED
Thu Aug 25 10:49:12 CEST 2011


On 25.8.2011 10:32, Kostis Sagonas wrote:
> On 08/24/11 17:51, Ladislav Lenart wrote:
>> Hello.
>>
>> > I was told that the timeout=0 reply from init/1 is has some implicit
>> > behavior that might be useful: it ensures that the
>> > handle_info('timout', State) is called before any other messages can
>> > be dispatched, which gives you a hook from init/1 that will run after
>> > the call to gen_server:start_link has returned. Feels hacky, to me --
>> > but the only way to handle certain cases.
>>
>> Just a side note to the special meaning of timeout=0 in init: the same
>> applies to any message sent to self() from the init/1 function, because
>> noone else knows my pid yet.
>
> Interesting...
>
> But would you care to elaborate a bit? What do you mean "noone else knows my pid yet" in an SMP environment with multiple schedulers and in the presence of the processes() function that can be called
> from anywhere? Am I missing something?

Nope, I've forgotten about processes() function but I consider it a
debugging aid and not a part of normal application operation. I would
not use (have never used) it in a production code. From this POV the
only "allowed" way to get a pid of a process is to receive it from a
message or as a return value of its start function.

If the process itself registers to some global service in its init
function, it has to do so after it has sent all required messages
to self.


Ladislav Lenart




More information about the erlang-questions mailing list