|
|
|
|
|
by GenericJam
1512 days ago
|
|
With Erlang it's necessary to separate the compiler from the VM. You are working around what the VM wants but the compiler is not a problem. The VM acts a bit like an operating system that can schedule its own processes and processes can send each other messages. In order to receive a message a process has to have a receive block and be capable of receiving the message (with an applicable pattern match). When a process is waiting for a message, it is set aside by the VM so it consumes very few resources (just a bit of memory). It is woken up when it receives a message.
This way a single 'program' can have many things going on at once and it is never blocking.
From the programmer's perspective it feels like you are writing synchronous code but you are getting async behaviour 'for free'. wrt LFE specifically, Robert Virding, one of the founders of Erlang, really likes languages and Lisp in particular so he wrote one for the BEAM. It just has some special accommodations to be able to send/receive (and I think pattern recognition too). |
|
I wish people would stop saying this. Writing concurrent systems in BEAM requires thought if you want to avoid deadlocks, races, bottlenecks, and performance problems. It also can be a bit tricky because processes serve many roles at once: fault isolation, GC isolation, the unit of concurrency, and the unit of synchronization.
Yes, a process can unleash concurrency and parallelization. But you also use processes to do things synchronously since a process goes through its mailbox one message at a time. You can accidentally bottleneck your system because of this.
Regardless, it does make it easier to write certain types of programs.