Producer/Consumer Workbench
Message Passing Solution


The producer consumer problem is a classic synchronization problem. The producer generates items that are consumed by the consumer. When the producer and consumer run on the same machine, they share a common buffer where items are placed by the producer and retrieved by the consumer. When the processes execute on different machines they have to communicate via message passing through a network. Messages sent by the producer to the consumer are stored in the consumer's input buffer until they are consumed. Since the buffer has finite length (8 slots in our example), the producer should not send any more messages when the consumer's buffer is full. For that purpose, the producer will only send a message to the consumer when it receives an empty message (a container) from the consumer.By restricting the number of containers to eight (the size of the consumer's input buffer) we guarantee that the producer will not send more messages than can be stored by the consumer. The following important conditions have to be satisfied by the producer and consumer:

The workbench that you are about to see, shows the code for the producer and consumer process as well as the input buffers for each process. Containers are indicated by the letter C. You can execute the workbench in a step-by-step mode by pushing the STEP button below each process. This will advance the process through its code. You will be able to see messages being sent and received by the processes. A status window below each process indicates if the process is running or sleeping on a particular condition. You can also execute the workbench in an animation mode by pushing the ANIMATE button. You will see controls that allow you to change the animation speed and the time it takes for a producer to produce an item and for a consumer to consume an item.

Workbench