Critical section (CS)

At any point in time, only 1 process can execute in the critical section.


This makes our mutations atomic.

For instance, suppose we had 2 processes executing concurrently, writing to file. They will write in an interleaving fashion. However, if we want 1 process to write, followed by second process, we need someway to control that behaviour.


  • We want only 1 process to access critical section at once
  • At least 1 process should be accessing


  • A process should eventually execute

    Bounded wait. If this doesn’t happen, the resources are blocked forever.

  • Other processes outside of the critical section should not block the process within. Otherwise this leads to deadlock.

Another interesting occurrence of this is livelock. This happens when processes change state, to avoid deadlock. If that’s all they do, this is a livelock.


naive Critical section implementation

peterson’s algorithm

Using testandset instruction