Subject โ€“ Operating System Topic โ€“ Process Synchronization (example based on Algo-2).

Subject โ€“ Operating System Topic โ€“ Process Synchronization (example based on Algo-2).



play-rounded-fill play-rounded-outline play-sharp-fill play-sharp-outline
pause-sharp-outline pause-sharp-fill pause-rounded-outline pause-rounded-fill
00:00
ยฉ 2018 Flowplayer ABAbout FlowplayerGPL based license

Here is a GATE-focused explanation for:


Contents [hide]

๐ŸŽ“ 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


โš™๏ธ 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:

  • 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:

  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:

  • 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!

Subject โ€“ Operating System Topic โ€“ Process Synchronization (example based on Algo-2).

OPERATING SYSTEMS PROCESS SYNCHRONIZATION



Leave a Reply

Your email address will not be published. Required fields are marked *

error: