The Critical Section Problem

The Producer-Consumer problem that we discussed is a particular example of a more general problem called the critical section problem, which is the need to define a set of rules that the coorporating processes should follow when attempting to change variables that are shared by the processes. The lines of code that modify the value of at least one shared variable are called the critical section. The goal is to find a way to alert all the processes that one of them is currently executing code inside a critical section so that the other processes must wait for the current process to finish its work.

The code preceding the critical section, and which controls access to the critical section, is called the entry section. It acts like a carefully controlled locking door. The code following the critical section is called the exit section. It generally releases the lock on someone else's door, or at least lets the world know that they are no longer in their critical section.

The rest of the code not included in either the critical section or the entry or exit sections is termed the remainder section.