0% found this document useful (0 votes)
14 views

System Software and Operating System 05 - Daily Class Notes

Uploaded by

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

System Software and Operating System 05 - Daily Class Notes

Uploaded by

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

1

UGC NET

DAILY
CLASS NOTES
Computer

System Software and Operating System


Lecture – 5
Process Synchronization and Critical
Section
2

Process Synchronization and Critical Section


Content:-

1. Process Synchronization
2. Critical Section Definition
3. Requirement of Critical section solution
4. Critical section Algorithms
5. Classic synchronization problems

Process Synchronization: It is a mechanization to ensure a systematic sharing of resources amongst concurrent


processes.

Critical Section:-

It refers to the code segment of a process/job whereby it accesses a shared resource.

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.

Critical section solutions:-

The general structure of critical section solution will be:-

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:-

I finished with it. Now you’re it.

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

Let me have it, after you finish with it.


4

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.

Typedefenum Boolean {false, true};

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 3 (Peterson’s Algorithm)

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.

It has two variables turn & flag both.

Classical Synchronization Problems:-

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.

2. Dining Philosopher’s Problem: Dining philosopher’s problem is the classical problem of


synchronization.

The problem stated as follows:-


a. There are N philosophers, sitting around a round dining problem
b. There are N plates, placed on the table each plate in front of a philosopher
c. There are N chopsticks, placed between the plates.
d. There is a bowl of spaghetti placed at the centre of the table.
e. Whenever, a philosopher feels hungry, he will attempt to pick up two chopsticks, which are shared
with the nearest neighbours. If any of hisneighbourhappens to be eating at that time, the philosopher
has to wait.
f. When, the hungry philosopher is able to get two chopsticks, he pours spaghetti in his plate and eats.
g. After, he finished to eat he places the chopsticks back on the table and starts to think. Now, the
chopstick is available for his neighbours.

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.

3. Sleeping Barber Problem :- The problem can be stated as follows


a. A hair cutting saloon has n chairs in its waiting room and 1 chair in the barber’s cabin for giving
hair-cut.
b. If there is no customer arrives at the saloon, the barber goes to sleep.
c. When, a customer arrives at the saloon one of the following happens:-
i. If there is no customer in the saloon, the customer walks into the hair-cutting
cabin, wakes up the barber and starts getting the hair cut
ii. If a customer is already getting hair-cut in the barber cabin, then the customer
looks for an empty chair in the waiting room. If a chair is empty then the customer
occupies an empty chair as per his order of arrival and waits for his turn. But if no
chair is empty in waiting room, then the customer walks away, without getting a
hair-cut.
d. When a customer, finishes getting the hair cut, he leaves the barber’s cabin and sends the next
waiting customer (as per FCFS order) to the barber’s cabin and then leave the saloon.

4. Readers and Writers Problem :- The problem can be stated as follows:


a. A number of cooperating processes are accessing a shared file or database.
b. Some of the cooperating processes need to only read the data. These processes cab be
referred as READERs.
c. Other cooperating processes needs to modify the data. These can be referred as WRITERS.
d. It is to be ensured that when the WRITER is in its critical section, no other READER or
WRITER can execute in critical section.
e. When a READER is in its critical section then other READERs (not WRITERS) can also
enter their critical sections.

PW Web/App : https://smart.link/7wwosivoicgd4
Library - https://smart.link/sdfez8ejd80if

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy