Critical Section Problem With Two Process Solution (Algo-1) Deckers solution, Strict Alteration.

Critical Section Problem With Two Process Solution (Algo-1) Deckers solution, Strict Alteration.



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

The Critical Section Problem is a classic problem in operating systems and concurrent programming, where multiple processes need to access shared resources without causing data inconsistencies. One of the earliest solutions for two-process synchronization is Strict Alternation, also known as Dekker’s Algorithm (Algo-1).

Contents [hide]

Strict Alternation Solution (Algorithm-1)

Concept:
In the strict alternation method, processes take turns to enter their critical section by maintaining a shared variable turn.

Algorithm

Let:

  • turn be a shared variable that alternates between 0 and 1.
  • P0 and P1 be the two processes.
  1. Process P0:

    while (turn != 0); // Wait until it's P0's turn
    // Critical Section
    turn = 1; // Give turn to P1
  2. Process P1:

    while (turn != 1); // Wait until it's P1's turn
    // Critical Section
    turn = 0; // Give turn to P0

Issues with Strict Alternation

Lack of Progress:

    • If one process does not need to enter its critical section, the other process is still forced to wait, leading to unnecessary delays.
  1. Busy Waiting:
    • The waiting process continuously checks the value of turn, leading to CPU wastage.
  2. Not Truly Concurrent:
    • A process can be blocked even when the critical section is available.

Improved Solution: Dekker’s Algorithm

To overcome the drawbacks of strict alternation, Dekker’s Algorithm introduces an additional mechanism using flags (flag[0] and flag[1]) to ensure mutual exclusion while allowing flexibility.

Would you like a detailed explanation of Dekker’s Algorithm or other alternative solutions like Peterson’s Algorithm?



Leave a Reply

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

error: