OPERATING
SYSTEM: CSET209
Process Synchronization
Critical section problem (CSP)
CONTENT
Synchronization constructs
S
❑ A process, A, attempts to modify data in a specific memory location. Simultaneously, another
process, B, attempts to read data from the same memory location. Consequently, there is a
significant likelihood 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.
RACE CONDITION S
❑ 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.
THE CRITICAL SECTION PROBLEM S
Consider system of n processes {p0, p1, … pn-1}
Each process has critical section segment of code
Process may be changing common variables, updating table, writing file, etc.
When one process in critical section, no other may be in its critical section
Critical section problem is to design protocol to solve this
Each process must ask permission to enter critical section in entry section, may
follow critical section with exit section, then remainder section.
SECTIONS OF A PROGRAM IN OS S
REQUIREMENTS OF SOLUTION TO CRITICAL-SECTION PROBLEM S
1. Mutual Exclusion - If process Pi is executing in its critical section, then no other
processes can be executing in their critical sections.
2. Progress - If no process is executing in its critical section and there exist some
processes that wish to enter their critical section, must be permitted without any
delay.
3. Bounded Waiting/No starvation - A bound must exist on the number of times that
other processes are allowed to enter their critical sections while another is waiting.
PETERSON’S SOLUTION
SEMAPHORE
SEMAPHORE
THANK YOU
?