Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Mutual Exclusion in Synchronization

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

During concurrent execution of processes, processes need to enter the critical section (or the section of the program shared across processes) at times for execution. It might so happen that because of the execution of multiple processes at once, the values stored in the critical section become inconsistent. In other words, the values depend on the sequence of execution of instructions – also known as a race condition. The primary task of process synchronization is to get rid of race conditions while executing the critical section. 

This is primarily achieved through mutual exclusion

Mutual exclusion is a property of process synchronization which states that “no two processes can exist in the critical section at any given point of time”. The term was first coined by Dijkstra. Any process synchronization technique being used must satisfy the property of mutual exclusion, without which it would not be possible to get rid of a race condition. 

The need for mutual exclusion comes with concurrency. There are several kinds of concurrent execution:

  1. Interrupt handlers
  2. Interleaved preemptively scheduled processes/threads
  3. Multiprocessor clusters, with shared memory
  4. Distributed systems
  • Mutual exclusion methods are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections • Requirement of mutual exclusion is that, when process P1 is accessing a shared resource R1 then on other process should be able to access resource R1 until process P1 has finished its operation with resource R1.
  • Examples of such resources include files, I/O devices such as printers and shared data structures.
  • Approaches to implementing mutual exclusion: 

1. Software method: Leave the responsibility with the processes themselves. These methods are usually highly error-prone and carry high overheads.

2. Hardware method: Special-purpose machine instructions are used for accessing shared resources. This method is faster but cannot provide complete solution. Hardware solution cannot give guarantee the absence of deadlock and starvation.

 3. Programming language method: Provide support through the operating system or through the programming language.

Requirements of mutual exclusion:

  1. At any time, only one process is allowed to enter in its critical section.
  2. Solution is implemented purely in software on a machine.
  3. A process remains inside its critical section for a bounded time only.
  4. No assumption can be made about relative speeds of asynchronous concurrent processes.
  5. A process cannot prevent any other process for entering into critical section.
  6. A process must not be indefinitely postponed from entering its critical section.

In order to understand mutual exclusion, let’s take an example. 


In the clothes section of a supermarket, two people are shopping for clothes.

Boy A decides upon some clothes to buy and heads to the changing room to try them out. Now, while boy A is inside the changing room, there is an ‘occupied’ sign on it – indicating that no one else can come in. Girl B has to use the changing room too, so she has to wait till boy A is done using the changing room. 

Once boy A comes out of the changing room, the sign on it changes from ‘occupied’ to ‘vacant’ – indicating that another person can use it. Hence, girl B proceeds to use the changing room, while the sign displays ‘occupied’ again.
 The changing room is nothing but the critical section, boy A and girl B are two different processes, while the sign outside the changing room indicates the process synchronization mechanism being used.

My Personal Notes arrow_drop_up
Last Updated : 24 Apr, 2023
Like Article
Save Article
Similar Reads