
- OS - Home
- OS - Needs
- OS - Overview
- OS - History
- OS - Components
- OS - Structure
- OS - Architecture
- OS - Services
- OS - Properties
- OS - TAT & WAT
- OS Processes
- OS - Processes
- OS - Process Scheduling
- OS - Scheduling Algorithms
- FCFS Scheduling Algorithm
- SJF Scheduling Algorithm
- Round Robin Scheduling Algorithms
- HRRN Scheduling Algorithms
- Priority Scheduling Algorithms
- Multilevel Queue Scheduling
- Context Switching
- Operations on Processes
- Lottery Process Scheduling
- Predicting Burst Time SJF Scheduling
- Race Condition Vulnerability
- Critical Section Synchronization
- Mutual Exclusion Synchronization
- Process Control Block
- Inter Process Communication
- Preemptive and Non-Preemptive Scheduling
- Operating System - Deadlock
- Introduction to Deadlock in Operating System
- Conditions for Deadlock in Operating System
- OS Synchronization
- Operating System - Process Synchronization
- Operating System - Critical Section
- Operating System - Semaphores
- Operating System - Counting Semaphores
- Operating System - Mutex
- Operating System - Lock Variable in Process Synchronization
- Operating System - Turn Variable in Process Synchronization
- Operating System - Bounded Buffer Problem
- Operating System - Reader Writer Locks in Process Synchronization
- Operating System - Test Set Lock in Process Synchronization
- Operating System - Peterson Solution in Process Synchronization
- Operating System - Monitors in Process Synchronization
- Operating System - Sleep and Wake in Process Synchronization
- OS Memory Management
- OS - Memory Management
- OS - Virtual Memory
- OS Storage Management
- File Systems in Operating System
- Linked Index Allocation in Operating System
- Indexed Allocation in Operating System
- Structures of Directory in Operating System
- File Attributes in Operating System
- Operating System - Page Replacement
- Operating Systems - Thrashing
- Belady’s Anomaly in Page Replacement Algorithms
- Optimal Page Replacement Algorithm
- Operating System - Types
- Types of Operating System
- Batch Processing Operating System
- Multiprocessing Operating System
- Hybrid Operating System
- Monolithic Operating System
- Zephyr Operating System
- Nix Operating System
- Blackberry Operating System
- Garuda Operating System
- Tails Operating System
- Clustered Operating System
- Haiku Operating System
- AIX Operating System
- Solus Operating system
- Tizen Operating System
- Bharat Operating System
- Fire Operating System
- Bliss Operating System
- VxWorks Operating System
- Embedded Operating System
- Single User Operating System
- OS Miscellaneous
- OS - Multi-threading
- OS - I/O Hardware
- OS - I/O Software
- OS - Security
- OS - Linux
- OS Useful Resources
- OS - Quick Guide
- OS - Useful Resources
- OS - Discussion
Mutual Exclusion in Synchronization
What is Mutual Exclusion?
Mutual exclusion implies that only one process can be inside the critical section at any time. If other processes need to execute in their critical sections, they must wait until it is free.
When more than one process wants to access or update a shared resource, i.e. get in their critical sections, if they execute simultaneously, race condition may occur leading to inconsistent results. In order to avoid race condition, the process synchronization technique should satisfy the mutual exclusion criteria.
Explanation
A process often needs to perform operations like accessing or updating shared resources like a common variable, a table of indexes or a shared file. When the process is doing so, it is said to be executing in its critical section. In the critical section, if the executing process is interrupted by another process which updates the shared resource in a different way, race condition occurs and the value of the shared resource become invalid.
Synchronization mechanisms are techniques that ensure that processes are executed in such a manner so that the state of the system and common data structures are consistent at all times. In order to avoid race conditions, the synchronization techniques make sure that the instructions of the operations in the critical section are executed as a single unit, i.e. in an atomic manner. Atomicity is guaranteed through mutual exclusion, through which only one process can execute in the critical section at a particular time.
Requisites of Mutual Exclusion
- Only one process can enter its critical section at a particular time.
- A process is permitted to execute in its critical section only for a bounded time.
- No process (which is not in its critical section) can prevent another process from entering into its critical section.
- No process must wait indefinitely to enter its critical section.
Techniques of Mutual Exclusion in Synchronization
Mutual exclusion can be achieved using a variety of strategies, such as the following −
Locks / Mutex
Synchronization primitives called locks or Mutex (short for mutual exclusion) are implemented to maintain consistency of the value or status of the shared resources. There are two possible states for a lock: locked and unlocked. An operating system or procedure must obtain the lock before being able to utilize the resource that is shared. The requesting string is going to be restricted as long as the lock has been released if it has already been locked by a distinct thread.
Semaphore
Semaphore is an advanced synchronization tool. It uses two atomic operations, "wait()" and "signal()". The wait() instruction is used in the entry section to gain access to the critical section, while the signal() operation is used to release control of the shared resource. Semaphores can be of two types, binary semaphores and counting semaphores. In a counting semaphore, when a thread needs to enter the critical area, semaphores keep track of a counter and decrease it. The running thread becomes immobilized if the counter decreases, signifying that the critical portion has become in use.
Atomic Operations
Without using locks or semaphores, certain processors offer atomic operations which may be employed to guarantee mutual exclusion. Atomic operations are advantageous for modifying shared parameters because they are unbreakable and can't be stopped. A property of a variable may only be altered using atomic compare-and-swap (CAS) procedures, for instance, if the value of the variable coincides with the value that is anticipated.
Software-based Techniques
Mutual exclusion can be achieved using a variety of software-based algorithms and strategies, including Peterson's algorithm, Dekker's algorithm, or Lamport's bakery algorithm. These techniques make a guarantee that only a single thread at one point is able to utilize the critical component by combining factors, flags, and busy-waiting.
Practical Instances of Mutual Exclusion in Synchronization
A few instances of mutual exclusion in synchronization that can occur in real life −
Printer Spooling
Several procedures or individuals may ask for printed documents at once in an OS with a number of users. Mutual exclusion is used to guarantee that just one process at the moment has access to the printer. In order to provide restricted access to the printer, avoid conflicts, and guarantee that printed positions are dealt with in the proper order, a lock or semaphore is used.
Bank Account Transactions
Many people may simultaneously try to obtain and alter their financial accounts in an electronic banking system. In order to avoid problems like overloading or erratic accounts, mutual exclusion is required. A single transaction is allowed to access a certain bank account at a time using locks or other synchronization primitives, maintaining the confidentiality of the information and avoiding conflicts.
Traffic Signal Control
Traffic signals at a crosswalk must be coordinated in order to safely manage the movement of transport vehicles. In order to avoid competing communication from being displayed at once, mutual exclusion is used. One indicator is allowed to be present at a time thanks to the mutual exclusion rule, which promotes efficient and organized traffic flow.
Resource Allocation in Shared Database
Mutual exclusion is essential to preserving information consistency in database systems where various procedures or transactions access information that is shared concurrently. For instance, mutual exclusion mechanisms make absolutely certain that just a single transaction is able to alter identical data at a time, hindering disagreements and maintaining data integrity when two separate operations try to alter the same information concurrently.
Accessing Shared Memory in Real-Time Systems
Mutual exclusion is required in real-time systems in which operations or procedures require shared memory to facilitate interaction or cooperation. Important memory-sharing regions are protected using synchronization basic functions like locks or semaphores, which make sure that only a single assignment is able to use and alter the area of shared memory at once.