UNIT 3 OS
UNIT 3 OS
(ii) Co-operating Processes:- These are the processes which can affect or
get affected by other processes during execution. Co-operating processes
can share data with another processes in simultaneous execution.
Why we need IPC?
There are several reasons which allows processes to co-operate:-
(iii) Modularity
(iv) Convenience
Race condition
Race condition is a situation arise due to concurrent execution of more
than one processes which are accessing and manipulating the same
shared data and the result of execution depends upon the specific order
where the access take place.
Figure :5
solution to synchronization problem(Cont.…)
Analysis:-
(i) Mutual Exclusion is assured as only one process can access the
critical section at any time.
(ii) Progress is also assured, as a process outside the critical section
does not block other processes from entering the critical section.
(iii) Bounded Waiting is preserved as every process gets a fair chance.
Disadvantages:-
(i) It involves Busy waiting.
(ii) It is limited to 2 processes.
solution to synchronization problem(Cont.…)
Strict Alteration:-
Turn Variable or Strict Alternation Approach is the software
mechanism implemented at user mode. It is a busy waiting solution
which can be implemented only
for two processes. In this approach,
A turn variable is used which is actually
There are two main types of semaphores i.e. counting semaphores and
binary semaphores. these are given as follows
Semaphore
Counting Semaphores:- These are integer value semaphores and have
an unrestricted value domain. These semaphores are used to coordinate
the resource access, where the semaphore count is the number of
available resources. If the resources are added, semaphore count
automatically incremented and if the resources are removed, the count
I decremented.
Binary Semaphores:- The binary semaphores are like counting
semaphores but their value is restricted to 0 and 1. The wait operation
only works when the semaphore is 1 and the signal operation succeeds
when semaphore is 0. It is sometimes easier to implement binary
semaphores than counting semaphores.
Monitor
?• A more elevated level synchronization primitive.
• A monitor is a bunch of techniques, variables, and information
structures that are completely assembled in an exceptional sort of
module or bundle.
• Procedures may call the strategies in a monitor at whatever point
they need to, however, they can't directly get to the monitor's
interior data structures from methodology announced outside the
monitor.
• Monitor have a significant property for accomplishing common
rejection: just one procedure can be dynamic in a monitor at any
moment.
• At the point when a procedure calls a monitor technique, the initial
hardly any directions of the method will verify whether some other
procedure is as of now dynamic inside the monitor .
• Assuming this is the case, the calling procedure will be suspended
until the different procedure has left the monitor. On the off
chance that no different procedure is utilizing the monitor, the
calling procedure may enter.
Producer consumer problem using monitor
• The arrangement proposes condition factors, alongside two
procedures on them, wait and signal.
• At the point when a monitor method finds that it can't proceed
(e.g., the maker finds the buffer full), it does a lookout for some
condition variable, full.
• This activity causes the calling procedure to block. It additionally
permits another procedure that had been recently block from
entering the screen to enter now.
Producer consumer problem using monitor
• This different procedure the customer, can awaken its dozing
accomplice by doing a sign on the condition variable that its
accomplice is looking out for.
• To abstain from having two dynamic procedures in the monitor
simultaneously a sign explanation may show up just as the last
proclamation in a monitor method.
• On the off chance that a sign is done on a condition variable on
which a few procedures are pausing, just one of them, controlled by
the framework scheduler, is retrieve.
Producer consumer problem using monitor
Figure :9
Reader’s & Writer Problem
• Reader’s writer problem is a one of the example of a classic
synchronization problem.
• Consider below situation when resource shared between
number of people.
• If one user is accessing the file so at the same time no other user
can read and write that same file. Otherwise change will not
reflects.
• However different users can read same file simultaneously.
Reader’s & Writer Problem
• This situation consider as reader’s and writer’s problem
• Lets take a look into problem statement more.
• Two operation we consider here one is Read operation and
another is write operation.
• We have two user consider here one is reader and another one is
writer.
• If one reader is using file and one writer come to access that
same file is a problem (R + W = Problem)
• If one writer is using file and one reader come to to access same
file is a problem (W + R = Problem)
Reader’s & Writer Problem
• If one writer is using file and another write come to access same file is
a problem. (W + W = Problem)
• If one reader is using file and another reader come to access same file
so no problem (R + R = No problem).
• This four case we have to consider.
• Here we use semaphore because here synchronization requires to
take care of given cases.
Reader’s & Writer Problem
Figure :11
Figure :10
Dining Philosopher’s Problem
As we take a look in given figure five philosopher ( P0,P1,P2,P3,P4)
seating on dining table and given chopsticks (C0,C1,C2,C3,C4) to eat
food on table .each philosopher requires tow chopsticks at a same
time to eat food
At any instant, a philosopher is either eating
or thinking. If philosopher is eating have to
pick chopstick one from their left and one
from their right.
If philosopher is thinking it down
the chopstick on table.
Dining Philosopher’s Problem
For example philosopher P0 want to eat food it require two chop
stick C0 and C1 as consider to below here i = 0 for p0 as 0th position.
take_chopstick(i); = C0
take_chopstick((i+1) % N); =(0+1)mod5 = C1
Dining Philosopher’s Problem
Now discuss case 1: In which one by one philosopher is eating and
thinking . which is best case. So if
philosopher P0 is eating with
chopstick C0 & C1 then put the
chopstick and then other P1
philosopher is come to eat which
require chopstick C1 and C2 .as we
see chopstick is now available for
philosopher P1 because
philosopher P0 already put down
chopstick C1 after eating. So in this
Figure :13
case no problem occur
Dining Philosopher’s Problem
P0 S0,S1
P1 S1,S2
P2 S2,S3
P3 S3,S4
P4 S4,S0
Table:1
Figure :14
Dining Philosopher’s Problem
S0 S1 S2 S3 S4 Table:7
0 0 1 1 1
Reference
[1] https://www.geeksforgeeks.org/dining-philosopher-problem-using-
semaphores/
www.paruluniversity.ac.in