Vlad Dumitrescu (EAW)
Thu Feb 27 09:49:04 CET 2003
I wonder about a thing. The following fun is an often used way to ensure that one uses "the one and only" server called ?MODULE.
case whereis(?MODULE) of
Pid = proc_lib:spawn(?MODULE, init, ),
Now I just had to implement this functionality and I noticed that the above isn't really correct. In fact, I even got a case during tests when the error showed up.
case whereis(?SERVER) of
Pid = spawn(fun init/0),
%% some other process might have already registered it
%% since we last checked
case catch register(?SERVER, Pid) of
%% we're the real thing
%% other process got there first, use that one
Pid ! stop,
%% try again!
I thought to share this, as it might cause confusion. Maybe it's not so often the scheduler will interrrupt start() just in the wrong place, but as I said, it happened to me (in relation with the debugger running).
More information about the erlang-questions