how "synchronous" is exit?
Richard Carlsson
richardc@REDACTED
Wed May 31 10:54:36 CEST 2006
Damien Katz wrote:
> Just to be sure, am I guaranteed the 'DOWN' message
> will only be received *after* the whole linked process
> tree under Pid is killed?
No. There is no built-in concept of process trees in Erlang.
The down-message is only valid for the linked/monitored process.
> My code wants to kill that process tree and start a
> new one that modifies the same file. Incomplete writes
> are not a problems, but race conditions are. I have to
> be sure another process isn't still making writes to
> the file, so I have to make sure the whole process
> tree is dead.
Two ways of doing this:
1. Make supervision a part of your process tree structure,
so that each process in the tree is responsible for tracking
its immediate children, and children also need to watch their
parents so that they can terminate if their parent is killed.
This can get hairy if you want to make sure that it's foolproof.
If this is what you want, but don't want to roll your own
solution, then you should start reading up on OTP and
supervision trees.
2. Spawn a separate process that just does tracking and
nothing else. Let new processes in the tree send a message
to the tracker first thing when they are started, and have
the tracker add a monitor for each such process. If you use
links between processes in the tree (and do not trap signals),
they will all terminate if one of them does (e.g., the root
process of the tree). So to delete the tree, you kill one
process and send a message to the tracker to enter the
cleanup phase. The tracker will then wait until it has
received down-messages for all watched processes, and
finally send a 'done'-reply and terminate. For a new process
tree, start a new tracker process. This should be fairly
straightforward to implement.
/Richard
More information about the erlang-questions
mailing list