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 Djikstra. 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.
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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Mutual exclusion in distributed system
- Peterson's Algorithm for Mutual Exclusion | Set 1 (Basic C implementation)
- Maekawa’s Algorithm for Mutual Exclusion in Distributed System
- Lamport's Algorithm for Mutual Exclusion in Distributed System
- Peterson's Algorithm for Mutual Exclusion | Set 2 (CPU Cycles and Memory Fence)
- Ricart–Agrawala Algorithm in Mutual Exclusion in Distributed System
- Suzuki–Kasami Algorithm for Mutual Exclusion in Distributed System
- Inclusion-Exclusion and its various Applications
- Process Synchronization | Set 2
- Synchronization in Distributed Systems
- Introduction of Process Synchronization
- Monitors in Process Synchronization
- Semaphores in Process Synchronization
- Critical Section in Synchronization
- Peterson's Algorithm in Process Synchronization
- Dekker's algorithm in Process Synchronization
- Bakery Algorithm in Process Synchronization
- Lock Variable Synchronization Mechanism
- Priority Inheritance Protocol (PIP) in Synchronization
- Classical problems of Synchronization with Semaphore Solution
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.