Skip to content

Commit

Permalink
Process parallel job results in same order.
Browse files Browse the repository at this point in the history
First spawned processes should be scheduled in same order and also they
results or fails will be in same order in message queue. This code is
simpler and makes more efficient processing of results or killing in error
case.
  • Loading branch information
pichi committed Nov 27, 2013
1 parent 8ecc03a commit 70bf371
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/proper_statem.erl
Expand Up @@ -646,7 +646,7 @@ execute(Cmds, Env, Mod, History) ->
-spec pmap(fun((command_list()) -> parallel_history()), [command_list()]) ->
[parallel_history()].
pmap(F, L) ->
await(lists:reverse(spawn_jobs(F,L))).
await(spawn_jobs(F,L)).

-spec spawn_jobs(fun((command_list()) -> parallel_history()),
[command_list()]) -> [pid()].
Expand All @@ -656,15 +656,11 @@ spawn_jobs(F, L) ->
|| X <- L].

-spec await([pid()]) -> [parallel_history()].
await(Pids) ->
await_tr(Pids, []).

-spec await_tr([pid()], [parallel_history()]) -> [parallel_history()].
await_tr([], Acc) -> Acc;
await_tr([H|T], Acc) ->
await([]) -> [];
await([H|T]) ->
receive
{H, {ok, Res}} ->
await_tr(T, [Res|Acc]);
[Res|await(T)];
{H, {'EXIT',_} = Err} ->
_ = [exit(Pid, kill) || Pid <- T],
_ = [receive {P,_} -> d_ after 0 -> i_ end || P <- T],
Expand Down

0 comments on commit 70bf371

Please sign in to comment.