Critical Section Problem
- Consider a system consisting of n processes P0, P1, ..., Pn.
- Each process has a segment of code, called a critical section, in which the process may be changing common variables, updating a table, writing a file, and so on. It is section of code that requires access to shared resources.
- An important fact regarding this system is that when a process A is executing in its critical section, no other process B except A is allowed to execute in its critical section.
- No-two processes can execute in its critical section at the same time.
- However many processes may have a critical section code and all of them needs to be executed. So, The Critical Section Problem deals with creating a set of protocols so as to help the process cooperate.
The various parts of a code for Critical section are:
- Entry Condition: Process requests for permission to enter the critical section
- Critical section: A portion of code within a process that needs access to shared resources and that must not be executed while another process is in its critical section.
- Exit Condition: Every critical section must end with an exit condition which alerts the system regarding the exit.
A solution to a critical section problem must satisfy three conditions;
a) Mutual Exclusion: If a process A is executing in its critical section, then no other processes must execute in its critical section.
b) Progress: If no process is currently in its critical section, then only those process which are currently not in its remainder section can participate in deciding who will enter the Critical section next.
c) Bounded waiting: There exists a bound with regards to the number of times other process can enter its critical section between when a process has requested for critical section and when that request is granted