4 ms·
> Erlang can kill a process, but does not have cancellation, which causes a process to be halted and throw a cancellation exception from the point at which it w
by toast0 7y ago
> Erlang can kill a process, but does not have cancellation, which causes a process to be halted and throw a cancellation exception from the point at which it was halted so that clean up can be performed while unwinding.
Indeed, Erlang does not have a way to induce a catchable exception into a process stack from outside the process. Processes are isolated, and the way that processes interact with the world is through their mailbox.
The Erlang way (TM) is to let your processes crash (or be killed), but be supervised and restarted, and the new process will handle whatever state the world is in, and bring it to a good state (or it won't, and it will die, and the supervisor will die, and the system will restart, eventually).
You could certainly pepper you code with something like
receive cancel -> throw cancel after 0 -> ok end
In places where you might want to be cancelled, and send a cancel message as appropriate, to get something like what you're asking. But it wouldn't feel very Erlangy, and looking at the results of being explicit about everywhere you might want to be cancelled might lead you towards the premise of Let it Crash. There are a million and one ways that the system might fail during activity, and for most of them, the right thing to do is restart, pick up the pieces, and go forward from there if you can. You're going to have to handle that anyway in case of unexpected restarts due to hardware or software faults.
> A boot request is sent to a controller to boot up a processor returning a termination report. A run request is sent to code to run returning a value.
What do you mean by a processor here. Like a separate CPU, or is this a process / thread?
What is the relationship between this processor and the code, and the run request? What behavior is changing in this example?
> Because tail calls with state variables do not always work and Erlang does not have an assignment command, Erlang programs often use helper processes to temporarily hold state.
That Erlang programs often use processes to hold state is not a deficiency; that's how Erlang models the world. State is intended to be held in processes, and the way that they do that is through tail call recursion on the explicit state. Although, sometimes, some state is stored in the process dictionary (which is essentially a key-value store) or in ETS/Mnesia, which can be modeled as a process (but is implemented as shared memory), or in state held outside of Erlang (such as the filesystem, or other programs).
If you don't like the world model where state is held in processes, Erlang clearly isn't for you; but I find it's a model that fits well with distributed systems, and allows for complex systems to be built with small teams.
- ProfHewitt 7y ago> Code should not be peppered something like the following: receive cancel -> throw cancel after 0 -> ok end Instead, cancellation should trigger cleanup to make it easier to recover. If no clean up is needed, then it doesn't have to be done. Actors were designed for massively concurrent systems that are often physically distributed. Behavior change (including state change) is essential for Actors, e.g., security, performance, etc.