[erlang-questions] dialyzer: another race condition report

Joel Reymont <>
Sun Oct 23 21:20:57 CEST 2011


This one is from Joe's old TCP server which I'm planning to replace. 

Still, I thought I would ask. How do you fix this?

tcp_server.erl:81: The call erlang:register(Name::atom(),Pid::pid()) might fail due to a possible race condition caused by its combination with the erlang:whereis(Name::atom()) call in tcp_server.erl on line 73

start_raw_server(Port, Fun, Max, Length) ->
    Name = port_name(Port),
    case whereis(Name) of
        undefined ->
            Self = self(),
            Pid = spawn_link(fun() ->
                                     cold_start(Self, Port, Fun, Max, Length)
                             end),
            receive
                {Pid, ok} ->
                    register(Name, Pid),
                    {ok, Pid};
                {Pid, Error} ->
                    Error
            end;
        _Pid ->
            {error, already_started}
    end.

--------------------------------------------------------------------------
- for hire: mac osx device driver ninja, kernel extensions and usb drivers
---------------------+------------+---------------------------------------
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------




More information about the erlang-questions mailing list