0% found this document useful (0 votes)
34 views28 pages

Unit 2InterprocessCommunication

Uploaded by

Aditya Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views28 pages

Unit 2InterprocessCommunication

Uploaded by

Aditya Pandey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Unit -2

Interprocess Communication
Interprocess Communication
 Inter Process Communication (IPC) refers to a
mechanism, where the operating systems allow various
processes to communicate with each other.
 Processes should communicate in a well structured way
not using interrupts
 Three issues need to be taken care of:
◦ How one process can pass information to another
◦ Making sure two or more processes do not get in eachother’s way
◦ Proper Sequencing when dependencies are present
Race Conditions
 A race condition is an undesirable situation that
occurs when a device or system attempts to
perform two or more operations at the same time,
but because of the nature of the device or system,
the operations must be done in the proper
sequence to be done correctly.
Interprocess Communication
Race Conditions

Two processes want to access shared memory at same time

4
Critical Regions (1)

Four conditions to provide mutual exclusion


1. No two processes simultaneously in critical
region
2. No assumptions made about speeds or
numbers of CPUs
3. No process running outside its critical region
may block another process
4. No process must wait forever to enter its critical
region
5
Critical Regions (2)

Mutual exclusion using critical regions

6
A solution to critical section problem must satisfy
following three requirements:

 Mutual Exclusion: if process Pi is executing in its critical section, then no other

processes can be executing in their critical sections

 Progress: If no process is executing in its critical section and some processes

wish to enter their critical sections, then only those processes that are not

executing in their remainder section can participate in deciding which will enter

its critical section next, and this selection cannot be postponed

 Bounded Waiting: A bound must exist on the number of times that other
processes are allowed to enter their critical sections after a process has made a

request to enter its critical section and before that request is granted.
In this section we will examine different proposals for
achieving Mutual Exclusion

 Disabling Interrupts
 Lock variables
 Strict Alternation
 Peterson’s solution
 The TSL Instruction
Disabling Interrupts
 Its is the simplest solution on a single
processor System
 Each process should disable interrupts just

after entering its critical region


 Re-enable interrupts before leaving the

Critical region
 Disadvantage:

◦ Unwise to give power to a user process to turn off


interrupts
◦ Not suitable for systems with multicores
Lock Variables
 It is a software solution
 A single shared lock variable, initially 0
 When a process wants to enter its critical
region , it first tests the lock
 Disadvantage:
◦ Chances are there that 2 or more processes are in
critical region at the same time
Mutual Exclusion with Busy Waiting:
Strict Alternation

; ;

Proposed solution to critical region problem


(a) Process 0. (b) Process 1.

11
Peterson’s solution
TSL Instruction
Producer-Consumer Problem
 The problem describes two processes,
the producer and the consumer, who share a
common, fixed-size buffer used as a queue.
The producer's job is to generate data, put it
into the buffer, and start again. At the same
time, the consumer is consuming the data
(i.e., removing it from the buffer), one piece
at a time.
Sleep and Wakeup

Producer-consumer problem with fatal race condition


15
Semaphores
 Synchronization tool
 This is used in solving problems associated with
synchronization and to avoid race condition.
 These are integer variables which are greater than or
equal to 0.
 These variables can be accessed through two standard
atomic operations:
 wait(S) {
while(S<=0);
S--;
}

 Signal(S) {
S++;
}
Semaphores

The producer-consumer problem using semaphores 17


Mutexes

Implementation of mutex_lock and mutex_unlock

18
Monitors (1)

Example of a monitor
19
Monitors (2)

 Outline of producer-consumer problem with monitors


◦ only one monitor procedure active at one time
◦ buffer has N slots 20
Monitors (3)

Solution to producer-consumer problem in Java (part 1)


21
Monitors (4)

Solution to producer-consumer problem in Java (part 2)


22
Dining Philosophers (1)

 Philosophers eat/think
 Eating needs 2 forks
 Pick one fork at a time
 How to prevent deadlock

23
Dining Philosophers (2)

A nonsolution to the dining philosophers problem

24
Dining Philosophers (3)

Solution to dining philosophers problem (part 1) 25


Dining Philosophers (4)

Solution to dining philosophers problem (part 2) 26


The Readers and Writers Problem

A solution to the readers and writers problem


27
Message Passing

The producer-consumer problem with N messages


28

You might also like