Subject – Operating System Topic – Process Synchronization (example based on Algo-2).
Subject – Operating System Topic – Process Synchronization (example based on Algo-2).
Here is a GATE-focused explanation for:
Contents
- 1 ๐ Subject: Operating System
- 2 ๐ง Algo-2: Dekkerโs Algorithm (Two-Process Synchronization)
- 2.1 ๐ Purpose: Software-based solution to achieve mutual exclusion for 2 processes (P0 and P1)
- 2.2 โ๏ธ Shared Variables Used:
- 2.3 ๐จโ๐ป Process Pi’s Code (i = 0 or 1):
- 2.4 โ Explanation of Key Parts:
- 2.5 ๐งพ Example Scenario:
- 2.6 ๐ Satisfaction of Synchronization Requirements:
- 2.7 โGATE-Style Question:
- 2.8 Subject – Operating System Topic – Process Synchronization (example based on Algo-2).
- 2.9 OPERATING SYSTEMS PROCESS SYNCHRONIZATION
๐ Subject: Operating System
๐ Topic: Process Synchronization
๐งช Example Based on Algo-2 โ Dekkerโs Algorithm
๐ What is Process Synchronization?
In multiprocessing systems, multiple processes may try to access shared resources (like memory or files) simultaneously. This leads to race conditions if not properly synchronized.
To prevent this, process synchronization algorithms are used to manage access to the critical section (CS).
๐ง Algo-2: Dekkerโs Algorithm (Two-Process Synchronization)
๐ Purpose: Software-based solution to achieve mutual exclusion for 2 processes (P0 and P1)
๐ Historical Significance: One of the earliest algorithms that satisfies:
-
Mutual Exclusion
-
Bounded Waiting
-
Progress
๐จโ๐ป Process Pi’s Code (i = 0 or 1):
โ Explanation of Key Parts:
-
flag[i] = true: Process Pi wants to enter CS.
-
while (flag[1-i]): If the other process also wants to enter, check
turn
. -
If turn != i: It waits and gives a chance to the other process.
-
After exiting CS: Sets
turn
to the other process and resets its flag.
๐งพ Example Scenario:
-
P0 and P1 both want to enter CS.
-
Both set
flag[0] = true
andflag[1] = true
. -
Now, both check each otherโs flag:
-
If
turn = 1
, P0 waits and P1 proceeds. -
If
turn = 0
, P1 waits and P0 proceeds.
-
-
After exiting CS, the current process gives turn to the other.
๐ Satisfaction of Synchronization Requirements:
Requirement | Satisfied? | How? |
---|---|---|
Mutual Exclusion | โ | Only one process enters CS at a time |
Progress | โ | No process is blocked unnecessarily |
Bounded Waiting | โ | Each process eventually gets a turn |
โGATE-Style Question:
Q: In Dekkerโs algorithm, what ensures bounded waiting?
A. flag[]
B. turn
variable
C. Both A and B
D. None of the above
โ Answer: C โ Both are required to implement bounded waiting.
Would you like:
-
A diagram/flowchart of Dekkerโs Algorithm?
-
A comparison between Dekkerโs and Petersonโs Algorithm?
-
MCQs and practice problems for GATE?
Let me know!