IPC - ST
IPC - ST
IPC - ST
• Correctness requirements
– Never more than one person buys milk (First Rule)
– Someone buys if needed (Fourth Rule)
• This solution of this case (mutual exclusion) is called an
synchronization
InterProcess Communication (IPC)
Disabling Interrupts
• On a single-processor system, each process
– Disable all interrupts just after entering its critical region
– Re-enable them just before leaving it
A process can examine and updated shared memory
without fear that any other process will intervene
• Disadvantages
– Give user processes the power to turn off interrupts (if a process
dies while it is in its critical region → the system is indefinitely
blocked)
– On a multiprocessor, the disabling interrupts affects only the
CPU that executed the disable instruction while the other ones
will continue running and can access the shared memory
Disabling interrupts is often a useful technique within
the OS itself but is not appropriate for user processes
InterProcess Communication (IPC)
Lock Variables
while(TRUE) {
while (lock == 1); //waiting until lock sets to 0
lock = 1;
critical_region();
lock = 0;
nonCritical_region();
}
Process 1 Process 2
while(TRUE) { while(TRUE) {
while (lock == 1); while (lock == 1);
lock = 1; lock = 1;
critical_region(); critical_region();
lock = 0; lock = 0;
nonCritical_region(); nonCritical_region();
} }
InterProcess Communication (IPC)
Lock Variables
• The solution fails
occasionally
– both processes can be
simultaneously in their own
critical regions
• Process A reads the lock and
sees that it is 0
• Before it can set the lock to 1,
Process B is scheduled, run,
and set the clock to 1 (then
Process A set the clock to 1)
• Testing a variable until
some value appears is called
busy waiting (wastes CPU
time)
InterProcess Communication (IPC)
Strict Alternation
* Semaphore
* Monitor
* Mutexes
* Message Passing
InterProcess Communication (IPC)
Sleep and Wakeup
• Both Peterson and TSL have defect of requiring “busy waiting“
– Waste CPU time
– Priority inversion
InterProcess Communication (IPC)
Sleep and Wakeup
• Both Peterson and TSL have defect of requiring “busy waiting“
– Waste CPU time
CPU Critical Regions
– Priority inversion Priority: 5
B
InterProcess Communication (IPC)
Sleep and Wakeup
• Both Peterson and TSL have defect of requiring “busy waiting“
– Waste CPU time
CPU Critical Regions
– Priority inversion Priority: 5
A B
A B
A B
A B
A B
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Wakeup Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Sleep
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Wakeup
Consumer
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
Sleep
InterProcess Communication (IPC)
Producer-Consumer Problem
Producer
Consumer
Q&A
Next Lecture
• Scheduling
• Scheduling Criteria/ Properties
• Scheduling decisions are applied to determine which
processes are executed (algorithms or mechanism)
• Scheduling on Processes and Threads