[erlang-questions] Join equivalent
Christian S
chsu79@REDACTED
Fri Sep 8 14:12:51 CEST 2006
On 9/8/06, theeepan <theepan@REDACTED> wrote:
> Hi,
>
> Is there an equivalent function in Erlang to "C pthreads join"? This can
> semantically be implemented with linked process with 'receive to exit', but
> what I want to know is whether there is a direct BIF to call after spawn?
Short answer: No, not directly.
Longer answer:
You can use erlang:monitor/2 to follow the status of the process. See
the manual for this.
Different approach: By passing the spawned process your pid and having
it report back with a message to you when it has completed its task is
also an option. Psuedo-ish code:
Pid = spawn_link(M, F, [self()),
mystuff(),
receive
{done, Pid} ->
phew()
after 5000 ->
ohnoes()
end
If the spawned process fails, it will crash and bring you down as
well. This can be a good thing that moves error handling higher up in
abstraction.
PS.
The function rpc:pmap/3 could be a better api for you, depending on
what problem you are trying to solve.
More information about the erlang-questions
mailing list