Serialized Objects as Messages in a Pipe or Socket Channel. This is a simple example illustrating both synchronous and asynchronous message passing. We can implement the bounded buffer producer and consumer with a set of empty messages representing the buffer slots. Message Set Forms a Bounded Buffer. A producer puts the work to be done into a message passing channel that is called a bag of tasks because consumers reach into the bag to extract the next piece of work to do.
Threads can use semaphores and monitors to handle mutual exclusion and condition synchronization.
Suppose though the threads do not share memory but are in nodes that have private memories and CPUs on a LAN and suppose they still want to do condition synchronization to coordinate access to some shared resource. Suppose we also want to avoid a central server to avoid a bottleneck. In other words, nodes eventually respond to all request messages. One does the above while loop. Another handles requests from other nodes.