System Software and Operating System 05 - Daily Class Notes
System Software and Operating System 05 - Daily Class Notes
UGC NET
DAILY
CLASS NOTES
Computer
1. Process Synchronization
2. Critical Section Definition
3. Requirement of Critical section solution
4. Critical section Algorithms
5. Classic synchronization problems
Critical Section:-
Requirement of Critical Section Solution: An ideal critical section sution meet the following three
requirements:-
a. Mutual Exclusion: At a time, at most one of the cooperating processes should be executed in its critical
section.
b. Progress: whenever none of the cooperating processes is executing in critical section and of the some of
the cooperating process is waiting to enter their critical section, none of the waiting processes should
immediately enable to enter in the critical section. The decision must not be delayed indefinitely. This is
the termed as requirement to progress, which must be under all the possible conditions.
c. Bounded waiting: These must be exist a finite upper bound on the number of times that other
cooperating processes can enter their critical section, after process P1 has requested to enter into its
critical section and before the request is granted. Normally upper bound is one.
Do {
Entry Section
Critical Section
Exit Section
Remainder Section
} while (1);
3
Entry Section: This refers to the code segment of process that is executed when the process indents to enter in its
critical section.
Critical Section: This is the code segment, wherein the process will access a shared resource. At a time, only one
of the cooperating processes should be in its critical section. So, when the process is executing in the critical
section, it is enjoying an exclusive access to the shared resources. (Non-Shareable section)
Exit Section: It segment that is executed by a process, immediately after its exit from the critical section. In this
section, a process performs certain operations, indicating its exit from the critical section and thereby enables one
of the waiting processes to enter into the critical sections.
Remainder Section: This is the remaining part of a process’s code (excluding entry section, critical section, and
exit section). When the process is executing in this section, it implies that it is not waiting to enter its critical
section. So the processes executing in their remainder sections are not considered as candidates for entry into their
critical section.
Critical Section Algorithms: An idea of this algorithm is to solve a critical section problem should meet the
three requirements viz.
a) Mutual exclusion
b) Progress
c) Bounded Waiting.
Algorithm 1:-
This algorithm applies to a set of two processes only, say [P0, P1]. Both are cooperating through a shared integer
variable “turn”. At a time, its value will be either 0 or 1.
Int turn = 0;
It satisfied only Mutual exclusion and bounded waiting requirements. Hence, Progress is not meet by this
algorithm. So, the main limitation of algorithm is that it doesn’t meet the requirement of Progress.
Algorithm 2
This algorithm also works for the set of two processes only. Unlike algorithm 1, this algorithm takes into
consideration the need of process to enter its critical section. Boolean variable flag is used to synchronize two
cooperating process.
It satisfied only Mutual exclusion and bounded waiting requirements. Hence, Progress is not meet by this
algorithm. So, the main limitation of algorithm is that it doesn’t meet the requirement of Progress.
This algorithm meets all the three requirement of an ideal critical section solution. It is also a generic algorithm
that can be used for the synchronization of arbitrary set of N cooperating processes.
1. The Bounded Buffer Problem: Suppose, there is a producer process, which produces some data-time
that is being consumed by a consumer process. The producer is producing the data-items asynchronously.
It is possible that, at time, the provider may produce data-time at a rate faster than the consumer can
consume. So, we a limited (bounded) number of buffers to hold the data items, which are awaiting
consumption. So, the message communication is performed through shared memory.
Limitation of this Algorithm: It is possible that all philosophers may feel hungry almost at the same time. They
all will pick up their perspective left chopsticks simultaneously. Now, all will keep waiting for their respective
right chopstick forever. It is a deadlock condition and thus requirement of progress not meet.
5
A Deadlock free Algorithm: The algorithm can be modified such that an even-numbered philosopher (i.e.0, 2, 4,
6…) attempts to pick left chopstick first and then right one. Whereas, an odd numbered philosopher (1, 3, 5…)
attempts to pick the right chopstick first and then left one.
PW Web/App : https://smart.link/7wwosivoicgd4
Library - https://smart.link/sdfez8ejd80if