PPT: Process Synchronization | Operating System - Computer Science Engineering (CSE) PDF Download

Download, print and study this document offline
Please wait while the PDF view is loading
 Page 1


Process 
Synchronization in 
Operating Systems
Page 2


Process 
Synchronization in 
Operating Systems
Race Conditions
Definition
A situation where the outcome of 
process execution depends on the 
unpredictable order of execution.
Example Scenario
Two processes increment a shared 
variable counter = 0. Process A reads 
counter = 0, Process B reads counter 
= 0. Both increment and write back, 
resulting in counter = 1 (instead of 
2).
Solution
Enforce mutual exclusion in critical 
sections to prevent simultaneous 
access to shared resources.
Race conditions occur due to lack of synchronization when accessing shared resources. The key terms to understand 
are critical section (code accessing shared resources) and race condition (incorrect output due to concurrent access).
Page 3


Process 
Synchronization in 
Operating Systems
Race Conditions
Definition
A situation where the outcome of 
process execution depends on the 
unpredictable order of execution.
Example Scenario
Two processes increment a shared 
variable counter = 0. Process A reads 
counter = 0, Process B reads counter 
= 0. Both increment and write back, 
resulting in counter = 1 (instead of 
2).
Solution
Enforce mutual exclusion in critical 
sections to prevent simultaneous 
access to shared resources.
Race conditions occur due to lack of synchronization when accessing shared resources. The key terms to understand 
are critical section (code accessing shared resources) and race condition (incorrect output due to concurrent access).
Critical Section Problem
Definition
A protocol to ensure only one process executes its critical 
section at a time, preventing race conditions and maintaining 
data consistency.
Requirements
Mutual Exclusion: Only one process in the critical section
Progress: If no process is in the critical section, any 
process can enter
Bounded Waiting: Limited waiting time for processes
The structure of a process with a critical section follows this pattern:
do { Entry Section ³ Critical Section ³ Exit Section ³ Remainder Section } while (true);
The goal is to design entry and exit protocols that satisfy all requirements, ensuring safe concurrent execution.
Page 4


Process 
Synchronization in 
Operating Systems
Race Conditions
Definition
A situation where the outcome of 
process execution depends on the 
unpredictable order of execution.
Example Scenario
Two processes increment a shared 
variable counter = 0. Process A reads 
counter = 0, Process B reads counter 
= 0. Both increment and write back, 
resulting in counter = 1 (instead of 
2).
Solution
Enforce mutual exclusion in critical 
sections to prevent simultaneous 
access to shared resources.
Race conditions occur due to lack of synchronization when accessing shared resources. The key terms to understand 
are critical section (code accessing shared resources) and race condition (incorrect output due to concurrent access).
Critical Section Problem
Definition
A protocol to ensure only one process executes its critical 
section at a time, preventing race conditions and maintaining 
data consistency.
Requirements
Mutual Exclusion: Only one process in the critical section
Progress: If no process is in the critical section, any 
process can enter
Bounded Waiting: Limited waiting time for processes
The structure of a process with a critical section follows this pattern:
do { Entry Section ³ Critical Section ³ Exit Section ³ Remainder Section } while (true);
The goal is to design entry and exit protocols that satisfy all requirements, ensuring safe concurrent execution.
Synchronization Mechanisms
Hardware-Based Solutions
Test-and-Set: Atomic instruction to set a lock and return its previous value. Swap: Atomically exchanges values of two 
variables. Simple and fast for single-processor systems but causes busy waiting.
Software-Based Solutions
Peterson's Algorithm: For two processes, uses turn and flag variables. Dekker's Algorithm: Similar to Peterson's, ensures 
mutual exclusion between processes.
Higher-Level Solutions
Semaphores, Monitors, and Locks provide more abstract and easier-to-use synchronization primitives for developers.
The key focus is understanding the trade-offs between simplicity and efficiency in these different synchronization approaches.
Page 5


Process 
Synchronization in 
Operating Systems
Race Conditions
Definition
A situation where the outcome of 
process execution depends on the 
unpredictable order of execution.
Example Scenario
Two processes increment a shared 
variable counter = 0. Process A reads 
counter = 0, Process B reads counter 
= 0. Both increment and write back, 
resulting in counter = 1 (instead of 
2).
Solution
Enforce mutual exclusion in critical 
sections to prevent simultaneous 
access to shared resources.
Race conditions occur due to lack of synchronization when accessing shared resources. The key terms to understand 
are critical section (code accessing shared resources) and race condition (incorrect output due to concurrent access).
Critical Section Problem
Definition
A protocol to ensure only one process executes its critical 
section at a time, preventing race conditions and maintaining 
data consistency.
Requirements
Mutual Exclusion: Only one process in the critical section
Progress: If no process is in the critical section, any 
process can enter
Bounded Waiting: Limited waiting time for processes
The structure of a process with a critical section follows this pattern:
do { Entry Section ³ Critical Section ³ Exit Section ³ Remainder Section } while (true);
The goal is to design entry and exit protocols that satisfy all requirements, ensuring safe concurrent execution.
Synchronization Mechanisms
Hardware-Based Solutions
Test-and-Set: Atomic instruction to set a lock and return its previous value. Swap: Atomically exchanges values of two 
variables. Simple and fast for single-processor systems but causes busy waiting.
Software-Based Solutions
Peterson's Algorithm: For two processes, uses turn and flag variables. Dekker's Algorithm: Similar to Peterson's, ensures 
mutual exclusion between processes.
Higher-Level Solutions
Semaphores, Monitors, and Locks provide more abstract and easier-to-use synchronization primitives for developers.
The key focus is understanding the trade-offs between simplicity and efficiency in these different synchronization approaches.
Semaphores
Binary Semaphore
Values 0 or 1 only, similar to a 
mutex lock. Used for simple 
mutual exclusion scenarios.
Counting Semaphore
Any non-negative integer value. 
Used for managing multiple 
instances of a resource.
Atomic Operations
Wait (P): Decrements semaphore; 
blocks if value < 0. Signal (V): 
Increments semaphore; wakes a 
waiting process.
A semaphore is a synchronization tool (integer variable) that manages access to shared resources. For example, with 
Semaphore S = 1, Process 1 executes wait(S) making S = 0 and enters critical section. Process 2 then executes wait(S), 
making S = -1 and blocks. When Process 1 executes signal(S), S becomes 0 and Process 2 unblocks.
Semaphores are particularly useful for controlling access to a fixed number of resources in a system.
Read More
10 videos|141 docs|33 tests

FAQs on PPT: Process Synchronization - Operating System - Computer Science Engineering (CSE)

1. What is process synchronization and why is it important in operating systems?
Ans. Process synchronization is a mechanism that ensures that multiple processes or threads can operate concurrently without conflicting with each other. It is crucial in operating systems to prevent race conditions, where two or more processes attempt to change shared data simultaneously, leading to inconsistent results. Synchronization mechanisms like semaphores, mutexes, and monitors help manage access to shared resources, ensuring data integrity and reliable execution.
2. What are the common synchronization problems faced in operating systems?
Ans. Common synchronization problems include the producer-consumer problem, dining philosophers problem, and readers-writers problem. The producer-consumer problem involves coordinating the production and consumption of data between processes. The dining philosophers problem illustrates issues of resource allocation and deadlock. The readers-writers problem focuses on managing access for multiple readers and writers to a shared resource, balancing the need for concurrency with data consistency.
3. What are semaphores, and how do they work in process synchronization?
Ans. Semaphores are signaling mechanisms used to control access to shared resources in concurrent programming. They can be binary (taking values 0 or 1) or counting (allowing more than two states). A semaphore maintains a count that represents the number of available resources. Processes can 'wait' on a semaphore to access a resource or 'signal' when they have completed their use, thereby updating the count. This mechanism helps prevent race conditions and ensures orderly access to shared resources.
4. What is the difference between a mutex and a semaphore?
Ans. A mutex (mutual exclusion) is a locking mechanism that allows only one thread to access a resource at a time, ensuring exclusive access. In contrast, a semaphore can allow multiple threads to access a resource simultaneously depending on its count value. While both are used for synchronization, a mutex is generally simpler and used for mutual exclusion, whereas semaphores are more versatile and can be used for signaling between processes.
5. How does deadlock occur in process synchronization, and what are its prevention strategies?
Ans. Deadlock occurs when two or more processes are unable to proceed because each is waiting for the other to release a resource. This can happen when processes hold resources while waiting for others, leading to a circular wait condition. Prevention strategies include resource allocation graphs, avoiding circular wait by enforcing a strict order of resource allocation, and implementing timeout mechanisms that allow processes to release resources after a certain period, thus breaking the deadlock cycle.
Related Searches

Objective type Questions

,

shortcuts and tricks

,

Summary

,

Free

,

study material

,

past year papers

,

Semester Notes

,

Extra Questions

,

Previous Year Questions with Solutions

,

Sample Paper

,

video lectures

,

Viva Questions

,

PPT: Process Synchronization | Operating System - Computer Science Engineering (CSE)

,

PPT: Process Synchronization | Operating System - Computer Science Engineering (CSE)

,

Exam

,

MCQs

,

pdf

,

ppt

,

Important questions

,

PPT: Process Synchronization | Operating System - Computer Science Engineering (CSE)

,

practice quizzes

,

mock tests for examination

;