Inter-Process Communication

We will look at some of the issues related to this Inter-Process Communication or IPC, for short. Three primary issues come into play.

  1. Passing Information: How one process communicates information to another. Involves the challenge of data exchange between processes.
  2. Avoiding Interference: Ensuring that multiple processes coexist without interfering with each other. For example, preventing conflicts when two processes attempt to reserve the last seat on a plane simultaneously.
  3. Proper Sequencing with Dependencies: Ensuring correct order and synchronization when dependencies exist. For instance, if process A generates data and process B is responsible for printing, B must wait for A to produce data before initiating printing.

It's essential to note that these concerns also apply to threads, with information exchange being more straightforward due to their shared address space.

Race Condition

As you may be familiar with the topic from COE628, race conditions can occur when multiple processes attempt to access shared resources concurrently.

  1. Passing Information: If multiple processes try to write or read shared data simultaneously without proper synchronization, data corruption may occur.
  2. Avoiding Interference: Without proper synchronization, multiple processes might attempt to access and modify shared resources simultaneously, leading to conflicts and incorrect results.
  3. Proper Sequencing: Lack of synchronization may lead to the printing process attempting to print data before it is produced, resulting in incorrect sequencing.

Consider a spooler directory with numbered slots, capable of holding file names. Two shared variables, out (pointing to the next file to print) and in (pointing to the next free slot), are accessible to all processes.

Figure 4.1 Two processes want to access shared memory at the same time.

Figure 4.1 Two processes want to access shared memory at the same time.

At a given moment, slots $0$ to $3$ are empty, and slots $4$ to $6$ are filled with files queued for printing.

  1. Process A reads and copies the value of the shared variable in to a local variable next_free_slot, setting it to $7$.
  2. Context switching occurs, and Process B reads and copies the value of in to its local variable next_free_slot, also setting it to $7$.
  3. Process B stores its file name in slot $7$, increments the value of in to $8$, and context switching happens.
  4. Process A resumes, stores its file name in slot $7$, overwriting Process B's file name, and increments in to $8$.