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

12 Classical Synchronization Problems

Uploaded by

agrasen09
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

12 Classical Synchronization Problems

Uploaded by

agrasen09
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

OPERATING

SYSTEM:
ACSE0403A
 Classical synchronization
problem
LAB TOOL
 Producer consumer problem
 Dining philosopher problem
S

WHAT IS PROCESS SYNCHRONIZATION ?


 When two or more process cooperates with each other, their order of execution must be
preserved otherwise there can be conflicts in their execution and inappropriate outputs can
be produced.
 On the basis of synchronization, processes are categorized as one of the following two
types:
 Independent Process : Execution of one process does not affects the execution of other
processes.
 Cooperative Process : Execution of one process affects the execution of other
processes.

 Note: Process synchronization problem arises in the case of Cooperative process also
because resources are shared in Cooperative processes.
S

EXAMPLE:

 A process A tries changing data in a particular memory location. At the same time another
process B tries reading data from the same memory location. Thus, there is a high probability
that the data being read by the second process is incorrect.

Need of Synchronization-
 When multiple processes execute concurrently sharing some system resources.
 To avoid the inconsistent results.
S

RACE CONDITION
 A race condition is a condition when there are many processes and every process shares
the data with each other and accessing the data concurrently, and the output of
execution depends on a particular sequence in which they share the data and access.
 A race condition is a situation that may occur inside a critical section.
 Race conditions in critical sections can be avoided if the critical section is treated as an
atomic instruction.
S

SECTIONS OF A PROGRAM IN OS

1. Entry Section: This decides the entry of any process.

2. Critical Section: This allows a process to enter and modify the shared variable.

3. Exit Section: This allows the process waiting in the Entry Section, to enter into
the Critical Sections and makes sure that the process is removed through this section
once it’s done executing.

4. Remainder Section: Parts of the Code, not present in the above three sections are
collectively called Remainder Section.
S

SECTIONS OF A PROGRAM IN OS
S

THE CRITICAL SECTION PROBLEM


• Critical Section is the part of a program which tries to access shared resources. That resource
may be any resource in a computer like a memory location, Data structure, CPU or any IO
device.

• The critical section cannot be executed by more than one process at the same time; operating
system faces the difficulties in allowing and disallowing the processes from entering the critical
section.

• The critical section problem is used to design a set of protocols which can ensure that the Race
condition among the processes will never arise.

• In order to synchronize the cooperative processes, our main task is to solve the critical section
problem. We need to provide a solution in such a way that the following conditions can be
satisfied.
S

REQUIREMENTS OF SYNCHRONIZATION MECHANISMS


• Mutual Exclusion: If a process is executing in its critical section, then no other process is
allowed to execute in the critical section.
S

REQUIREMENTS OF SYNCHRONIZATION MECHANISMS


• Progress:
• Progress means that if one process doesn't need to execute into critical section then it
should not stop other processes to get into the critical section
• We use it when the critical section is empty, and a process wants to enter it. The processes
that are not present in their reminder section decide who should go in, within a finite time.
S

REQUIREMENTS OF SYNCHRONIZATION MECHANISMS

• Bounded Waiting:
• We should be able to predict the waiting time for every process to get into the critical
section. The process must not be endlessly waiting for getting into the critical section.
• Only a specific number of processes are allowed into their critical section. Thus, a
process needs to make a request when it wants to enter the critical section and when the
critical section reaches its limit, the system allows the process’ request and allows it into
its critical section..

• Architectural Neutral:
• It can run on any architecture without any problem.
• There is no dependency on the architecture.
S

SOLUTION TO CRITICAL SECTION PROBLEM

• Software based solution


• Peterson’s solution

• Hardware based solutions


• Disable interrupts
• Atomic instructions: TestAndSet and Swap

• OS solutions:
• Semaphore
S

A SIMPLE SOLUTION
• Bool turn;->indicate whose turn to enter CS
• T0 and T1: alternate between CS and remainder

Pros: Cons:
1. Pi’s critical section is executed 1. Progress is not satisfied since it requires strict
iff turn = i alternation
2. Pi is busy waiting if Pj is in CS 2. 2. A process cannot enter the CS more often
(mutual exclusion) than the other.
THANK YOU
?

You might also like