When Life Gives You No Global Variables, Use Message Passing
A note on distributed programming
Computer science recognizes two principal interprocess communication paradigms: shared memory and message passing.
Shared memory is virtually global RAM accessible to two or more processes. “Virtually global” means it looks like a contiguous address space for all processes, regardless of the physical contiguity and placement. In reality, a virtually global RAM may consist of one block of RAM or separate local RAMs connected by a global bus or network, including, but not limited to, Ethernet or WLAN. The shared memory holds global variables accessible to all involved processes. A modification of a global variable by one process is instantly visible to all other processes. Global variables are evil because they create dependencies that are hard to trace, but they are easy to use. We all know how to read and change their values.
When one places processes on different cores with disjoint RAMs, shared memory becomes hard or impossible to implement, even as a virtual abstraction. Message passing comes to the rescue. Processes willing to communicate resort to the operations send() and receive() to request and supply data explicitly. The methods send() and receive() supersede assignment to and readout from a global variable. Both methods can be…