Skip to content

Commit

Permalink
reap pmap processes when it is all done
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliff Moon committed Jan 17, 2009
1 parent ba7245f commit 2dd334e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions elibs/lib_misc.erl
Expand Up @@ -48,12 +48,15 @@ pmap(Fun, List, ReturnNum) ->
L = gather(N, length(List), Ref, []),
SuperParent ! {SuperRef, pmap_sort(List, L)}
end),
_Pids = [spawn(fun() ->
Pids = [spawn(fun() ->
Parent ! {Ref, {Elem, (catch Fun(Elem))}}
end) || Elem <- List],
receive
Ret = receive
{SuperRef, Ret} -> Ret
end.
end,
% i think we need to cleanup here.
lists:foreach(fun(P) -> exit(P, die) end, Pids),
Ret.

pmap_sort(Original, Results) ->
pmap_sort([], Original, lists:reverse(Results)).
Expand Down
8 changes: 4 additions & 4 deletions etest/lib_misc_test.erl
Expand Up @@ -2,16 +2,16 @@

pmap_test() ->
L = [0, 1, 2],
[0,1] = pmap(fun(N) ->
?assertEqual([0,1], pmap(fun(N) ->
timer:sleep(N),
N
end, L, 2).
end, L, 2)).

pmap_1_test() ->
L = [0],
[0] = pmap(fun(N) ->
?assertEqual([0], pmap(fun(N) ->
N
end, L, 1).
end, L, 1)).

reverse_bits_test() ->
3869426816 = reverse_bits(19088743),
Expand Down

0 comments on commit 2dd334e

Please sign in to comment.