ensure_started

Vladimir Sekissov <>
Sun Mar 23 19:07:23 CET 2003


Good day,

loop() ->
  receive
   Msg ->
    do_something,
    loop();
   please_die ->
     receive
       Msg -> % there are some messages, continue
         loop()
     after 0 -> % nobody wants to talk to me
       exit(shutdown)
     end
  end.

Best Regards,
Vladimir Sekissov

cpressey> I was wondering if there's a similar case when a process dies.  Is there a
cpressey> way to absolutely ensure that a process'es mailbox is empty before it
cpressey> dies?  Especially if more than one process is sending messages to the
cpressey> process.  Example:
cpressey> 
cpressey>   server() ->
cpressey>     receive
cpressey>       {Pid, Data} ->
cpressey>         Reply = do_stuff(Data),
cpressey>         Pid ! Reply,
cpressey>         server();
cpressey>       shut_yourself_down ->
cpressey>         % --> mightn't we get another message right here?
cpressey>         % --> if we do, the sender will never get a reply
cpressey>         exit(was_shut_down)
cpressey>     end.
cpressey> 
cpressey> -Chris



More information about the erlang-questions mailing list