OS2: Process Synchronization-Unit 4: Critical Section Problem
Consider a system consisting of n processes {P0, P1,…, Pn-1}. Each process has a segment of code called critical section, in which the processes may be changing common variables, updating a table, writing a file, etc. The important feature of the system is that, when one process is executing, in its critical section, no other process is to be allowed to execute in its critical section. Therefore the execution of the critical section by the processes is mutually exclusive in time. The critical section problem is to design a protocol that the processes can use to cooperate. Each process must request permission to enter its critical section. The section of code implementing this request is the entry section. The critical section may be followed by an exit section. The remaining code is the remainder section.
do {
entry section
critical section
exit section
remainder section
} while(1);
Figure 1.1
General structure of a typical process Pi
A solution to the critical section problem must satisfy the following three requirements:
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 some processes wish to enter their critical sections, then only those processes that are not executing in their remainder section can participate in the decision on which will enter its critical sectionnext, and this selection cannot be postponed indefinitely.
3. Bounded Waiting: there exists a bound on the number of times that other processes are allowed to enter their critical sections after a process has made request to enter its critical section and before that request is granted.
Based on these three requirements, we will discuss some solutions to critical section problem in this unit.
2.0
Objectives
At the end of this unit you should be able to:
• Explain the critical section problem
• State the different levels of critical section
• Define semaphores
• Define monitors
• Distinguish between monitors and semaphores