12 Classical Synchronization Problems
12 Classical Synchronization Problems
SYSTEM:
ACSE0403A
Classical synchronization
problem
LAB TOOL
Producer consumer problem
Dining philosopher problem
S
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
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 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
• 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
• 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
?