DIZNR INTERNATIONAL

Subject – Operating System Topic – Process Synchronization (example based on Algo-2).

Subject – Operating System Topic – Process Synchronization (example based on Algo-2).

https://www.gyanodhan.com/video/7B7.%20GATE%20CSEIT/Operating%20System/632.%20GATE%202015%20%20%20Subject%20-%20Operating%20System%20Topic%20-%20Process%20Synchronization%20%28example%20based%20on%20Algo-2%29.mp4

Here is a GATE-focused explanation for:


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:


Shared Variables Used:

c
boolean flag[2] = {false, false}; // flags to show intention to enter CS
int turn = 0; // indicates whose turn it is

Process Pi’s Code (i = 0 or 1):

c
// Entry Section
flag[i] = true;
while (flag[1 - i]) {
if (turn != i) {
flag[i] = false;
while (turn != i); // busy wait
flag[i] = true;
}
}

// ---- Critical Section ----

// Exit Section
turn = 1 - i;
flag[i] = false;


Explanation of Key Parts:


Example Scenario:

  1. P0 and P1 both want to enter CS.

  2. Both set flag[0] = true and flag[1] = true.

  3. Now, both check each other’s flag:

    • If turn = 1, P0 waits and P1 proceeds.

    • If turn = 0, P1 waits and P0 proceeds.

  4. 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:

Let me know!

Subject – Operating System Topic – Process Synchronization (example based on Algo-2).

OPERATING SYSTEMS PROCESS SYNCHRONIZATION