OS 3 InterProcessesCommunication
OS 3 InterProcessesCommunication
ECEG-5202
INTER-PROCESSES
COMMUNICATION
Outline
▪Introduction
▪Race condition
▪Critical region
▪Process synchronization
Next_free_slot
Disabling interrupt
◦ Disable all interrupts just after entering its critical region and re-enable them
just before leaving it
◦ No clock interrupts can occur
◦ Simple
◦ Not a good choice. Why?
◦ Gives user processes the power to turn off interrupts
◦ Doesn’t work in a system with multiprocessor
◦ Disabling interrupts affects only the CPU that executes the disable instruction, other
processes on other CPUs could access it
Peterson’s solution
◦ Same as Dekker’s solution but
simpler
Two processes share a common, fixed-size buffer. One of them, the producer, puts information into
the buffer, and the other one, the consumer, takes it out
◦ Problem
1. Producer wants to put a new item in the buffer, but it is already full
◦ Soln.: Producer goes to sleep
2. Consumer wants to remove an item from the buffer and sees that the buffer is
empty
◦ Soln.: Consumer goes to sleep
Question
◦ How can they share the turn variable in Peterson’s algorithm, or semaphores or a
common buffer?
Answer
1. Semaphores can be stored in the kernel and accessed only by means of
system calls
2. Most modern OSs offer a way for processes to share some portion of their
address space with other processes
3. Using shared files
◦ Solution
◦ Higher level synchronization primitive: Monitor