Erlang application stop 调用死锁
(金庆的专栏)
在application行为模块的start()中启动bson应用,在stop()中停止bson,
结果application:stop(bson)会死锁。
-module(my_app).
-behaviour(application).
%% Application callbacks
-export([start/2, stop/1]).
%% ===================================================================
%% Application callbacks
%% ===================================================================
start(_StartType, _StartArgs) ->
ok = application:start(bson),
{ok, Pid} = my_sup:start_link(),
{ok, Pid}.
stop(_State) ->
application:stop(bson),
ok.
参考 How to stop third-party Erlang applications
http://stackoverflow.com/questions/2305511/how-to-stop-third-party-erlang-applications
才明白stop()是回调,在回调中试图停止其他应用就会死锁。
stop()是应用控制器回调的,应用控制器在等待回调返回时,无法响应application:stop()请求,所以死锁了。