Sleep and Wakeup using Message Passing

So far we have discussed two different types of interprocess communication: semaphores and monitors. These methods work well on computers with shared memory, but they are not effective on distributed systems. Semaphores and monitors provide no machine to machine communication capability. The last method we will discuss,Message passing, solves this problem. Two primitives, SEND and RECEIVE are used in the message passing scheme. The SEND primitive sends a message to a destination process while the RECEIVE primitive receives a message from a specified source process. Message Passing works on distributed systems because these messages can be sent from machine to machine through a network.

Typically, each process has a mailbox; a buffer which receives all the messages which are sent to that process. The destination of the SEND and RECEIVE system calls is a process' mailbox, not the process itself.

The pictures above illustrate the SEND and RECEIVE primitives used in message passing. SEND takes two arguements, the destination mailbox and the message. RECEIVE also takes two arguements, the ID of the sender, and the message.

How is Mutual Exclusion implemented with Message Passing?

Several methods exist for implementing mutual exclusion with message passing. One method uses processes to regulate access to shared resources. A resource control process has a variable which records the status of a resource (free or busy), and a buffer which contains request messages from other processes.

This pictures shows an interaction between a process that wants to access a shared resource, and a resource control process. Three messages are sent here. Message (1) is a request for access to the resource. Process P1 then blocks, waiting for a reply from the resource control process. Message (2) is the reply sent by the control process. This message wakes up P1, and P1 now uses the resource. Message (3) informs the resource control process that P1 is done using the resource.

The code for this interaction looks like this:

P1:

send(control_process, "Give me resource");

receive(control_process, Message); // block while waiting for a reply

  
       {
        ...Critical Section...
       }

send(control_process, "Done with resource");


               
IPC Home    Subway    Solution   Sleep &   
  Page       Map       Types     Wake Up