Permalink
Browse files

Make spawn_link not fail with noproc if caller has already been sent …

…exit.
  • Loading branch information...
1 parent 7551932 commit 7393f373cb042b746c1014576ffbd450bbd5ce75 @esstrifork esstrifork committed Jan 29, 2014
@@ -89,7 +89,9 @@ public void link_to(ETask<?> task) throws Pausable {
}
public void link_to(EHandle handle) throws Pausable {
- if (!link_oneway(handle) || !handle.link_oneway((EHandle) self_handle())) {
+ if (link_oneway(handle)) {
+ handle.link_oneway((EHandle) self_handle()); // Ignore failure if linker has received SIG_EXIT
+ } else {
link_failure(handle);
}
}
@@ -301,7 +303,6 @@ public void mbox_remove_one() throws Pausable {
* @param is_erlang_exit2 TODO
*/
public final void send_exit(EHandle from, EObject reason, boolean is_erlang_exit2) throws Pausable {
-
if (log.isLoggable(Level.FINE)) {
log.log (Level.FINE, "exit " + from + " -> " + this + ", reason="+reason, new Throwable("trace"));
}
@@ -403,9 +404,10 @@ public void checkKill() {
/**
* @return
- */
- public boolean exists() {
- return pstate == STATE.INIT || pstate == STATE.RUNNING;
- }
+ */
+ public boolean exists() {
+ STATE ps = pstate; // Read volatile just once!
+ return ps == STATE.INIT || ps == STATE.RUNNING;
+ }
}
@@ -320,7 +320,7 @@ static EPort open_port(EProc proc, EObject portName, EObject portSetting)
if (task != null) {
// link this proc and the driver task
- task.link_to(proc);
+ proc.link_to(task);
ERT.run(task);
return task.self_handle();
@@ -174,7 +174,7 @@ public static EObject spawn_link(EProc proc, EObject mod, EObject fun, EObject a
EProc p2 = new EProc(proc.group_leader(), m, f, a);
- p2.link_to(proc);
+ proc.link_to(p2);
ERT.run(p2);
@@ -225,7 +225,7 @@ public static EObject spawn_opt(EProc self, EObject tup) throws Pausable {
EProc p2 = new EProc(self.group_leader(), m, f, a);
if (link) {
- p2.link_to(self);
+ self.link_to(p2);
}
if (priority != null) {
@@ -51,7 +51,7 @@ nontail_spawn_link_child_exits_abnormally_test() ->
|| _ <- lists:seq(1,N)]
end).
-%%% Tests propgation.
+%%% Tests propagation.
nontail_spawn_link_child_with_siblings_exits_abnormally_test() ->
N = 1000,
expect_to_leave_N_processes(0,
@@ -61,6 +61,15 @@ nontail_spawn_link_child_with_siblings_exits_abnormally_test() ->
end).
+%%% Tests propagation + possibility of having been sent exit when trying to link
+link_kill_race_test() ->
+ N = 10000,
+ expect_to_leave_N_processes(0,
+ fun() ->
+ [link_kill_race()
+ || _ <- lists:seq(1,N)]
+ end).
+
tail_nonlink_permanent_child() ->
spawn(fun() ->
spawn_link(fun() ->
@@ -136,6 +145,17 @@ nontail_spawn_link_child_with_siblings_exits_abnormally() ->
end)
end).
+link_kill_race() ->
+ Pid = spawn(fun() ->
+ io:format("B"),
+ spawn_link(fun() ->
+ io:format("C"),
+ receive never -> ok end
+ end),
+ receive never -> ok end
+ end),
+ exit(Pid,go_away).
+
expect_to_leave_N_processes(N, Action) when is_integer(N),
is_function(Action,0) ->
Before = processes(),

0 comments on commit 7393f37

Please sign in to comment.