Operating System - Process Synchronization Answers
1. Importance of Process Synchronization and Test-and-Set / Swap
Instructions
Process synchronization is used to coordinate multiple processes accessing shared resources. It prevents race cond
Importance:
• Prevents data corruption
• Avoids race conditions
• Ensures mutual exclusion
• Improves system reliability
Test-and-Set Instruction:
It is an atomic hardware instruction used to lock a critical section.
Pseudo Code:
while(TestAndSet(lock))
; // wait
Critical Section
lock = false;
Swap Instruction:
It exchanges values atomically between variables to control entry into critical section.
2. Structures of Multiprocessor Operating Systems
Main structures are:
1. Master-Slave Multiprocessing
2. Symmetric Multiprocessing (SMP)
3. Asymmetric Multiprocessing (AMP)
Symmetric Multiprocessing:
All processors are equal and share memory. Any processor can execute tasks.
Master-Slave:
One processor controls the system while others execute assigned tasks.
Asymmetric Multiprocessing:
Each processor performs specific dedicated tasks.
3. State Transition Diagram of Process
Process states:
• New
• Ready
• Running
• Waiting
• Terminated
Transitions:
New → Ready → Running → Waiting/Ready → Terminated
Ready state waits for CPU allocation. Running state executes instructions. Waiting state waits for I/O operations.
4. Critical Section Problem and Mutual Exclusion
Critical section is the part of program where shared resources are accessed.
Example:
Two processes updating same bank account simultaneously may produce wrong balance.
Mutual Exclusion Methods:
• Peterson’s Algorithm
• Semaphores
• Mutex Locks
• Monitors
Goal:
Only one process should execute inside critical section at a time.
5. Semaphore Concept with Wait and Signal
Semaphore is a synchronization variable used to control process access.
Operations:
wait(S):
S=S-1
if S < 0 then block process
signal(S):
S=S+1
if S <= 0 then wake process
Semaphores prevent race conditions and synchronize processes.
6. Types of Semaphore
1. Binary Semaphore:
Value is either 0 or 1. Used for mutual exclusion.
2. Counting Semaphore:
Value can be greater than 1. Used to manage multiple resources.
7. Situations Where Process Synchronization is Needed
Synchronization is needed in:
• Producer-Consumer Problem
• Readers-Writers Problem
• Dining Philosophers Problem
These problems involve shared resources and require coordination among processes.
8. Monitors During Process Scheduling
Monitor is a high-level synchronization construct.
Features:
• Only one process executes inside monitor at a time
• Uses condition variables
• Simplifies synchronization
Advantages:
• Easy to implement
• Reduces synchronization errors
• Provides automatic mutual exclusion
9. Drawbacks of Serializers and Solution
Drawbacks:
• Increased waiting time
• Reduced parallelism
• Performance overhead
Solution:
Synchronization techniques like semaphores and monitors improve resource sharing and reduce conflicts.
10. Path Expressions and Sequencing Concurrency
Path expressions specify execution order of operations.
Example:
read ; write
Meaning:
Write operation can occur only after read operation.
Concurrency operations:
• Sequencing
• Selection
• Iteration
• Parallel execution
11. Memory Management in Multiprocessor OS and Copy-on-Write
Design Issues:
• Memory consistency
• Cache coherence
• Memory allocation
• Synchronization
Copy-on-Write (COW):
Instead of copying immediately, processes share memory pages. Copy occurs only when modification happens.
Advantages:
• Saves memory
• Improves performance
• Efficient process creation