ensure_started

Chris Pressey cpressey@REDACTED
Sun Mar 23 20:55:22 CET 2003


On Fri, 21 Mar 2003 16:22:12 +0100 (MET)
Peter H|gfeldt <peter@REDACTED> wrote:

> On Feb 1, 1997 I wrote the following, addressed to the OTP developing
> team. I think it is still valid. 
> [...]
>         Put the register/2 part in the Module:init function, so that
>         the newly created process fails (and terminates if properly
>         programmed) if the name is already registered. Then there 
>         will be at most one process doing 'the thing'.

Wow, six years...

This got me thinking.  Although this may sound a bit harsh - isn't
register/2 perhaps a design flaw?  If it were register/1, and always
applied to self(), it would force you code process registration this way,
by the newly created process.

Is there ever a truly convincing reason to register a process that isn't
self()?

> [...]
> Concurrency is more difficult than you believe."

I believe it :)

I was wondering if there's a similar case when a process dies.  Is there a
way to absolutely ensure that a process'es mailbox is empty before it
dies?  Especially if more than one process is sending messages to the
process.  Example:

  server() ->
    receive
      {Pid, Data} ->
        Reply = do_stuff(Data),
        Pid ! Reply,
        server();
      shut_yourself_down ->
        % --> mightn't we get another message right here?
        % --> if we do, the sender will never get a reply
        exit(was_shut_down)
    end.

-Chris



More information about the erlang-questions mailing list