Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Question: You are required to analyze the software approaches (all attempts of

Dekker’s algorithms and Peterson’s Solution) for solving the mutual exclusion
problem. You have to devise the perfect and final solution (version of Dekker’s
Algorithm) in your solution.

Dekker’s Algorithm
Dekker's algorithm is the first known correct solution to the mutual
exclusion problem in concurrent programming. It allows two threads to share a
single-use resource without conflict, using only shared memory for
communication. Dekker’s algorithm was the first provably correct solution to the
critical section problem. It allows two threads to share a single-use resource
without conflict, using only shared memory for communication. It avoids the strict
alternation of a naïve turn-taking algorithm and was one of the first mutual
exclusion algorithms to be invented.
First version of Dekker’s solution

Problem in first version:


The problem arising in the above implementation is lockstep synchronization, i.e
each thread depends on the other for its execution. If one of the processes
completes, then the second process runs, gives access to the completed one and
waits for its turn, however, the former process is already completed and would
never run to return the access back to the latter one. Hence, the second process
waits infinitely then.
Second version of Dekker’s solution
Lockstep synchronization is removed. It is done by using two flags to indicate its
current status and updates them accordingly at the entry and exit section.
Problem in second version:
Mutual exclusion is violated in this version. During flag update, if threads are
stopped then both the threads enter into the critical section. Once the stopped
thread is restarted, also the same can be observed at the start itself, when both the
flags are false.

Third version of dekker’s solution


Critical section flag is set before entering critical section test to ensure mutual
exclusion.
Problem in third version:
This version failed to solve the problem of mutual exclusion. It also introduces
deadlock possibility, both threads could get flag simultaneously and they will wait
for infinite time.

Fourth version of Dekker’s solution


Here,  it sets flag to false for small period of time to provide control and solves the
problem of mutual exclusion and deadlock.
Problem in Forth version:
Indefinite postponement is the problem of this version. Random amount of time is
unpredictable depending upon the situation in which the algorithm is being
implemented, hence it is not acceptable in case of business critical systems.
Fifth version of Dekker’s solution
In this version, flavored thread motion is used to determine entry to critical section.
It provides mutual exclusion and avoiding deadlock, indefinite postponement or
lockstep synchronization by resolving the conflict that which thread should execute
first. This version of Dekker’s algorithm provides the complete solution of critical
section problems.
Peterson's Algorithm:
Peterson's algorithm is a concurrent programming algorithm for mutual
exclusion that allows two or more processes to share a single-use resource without
conflict, using only shared memory for communication. This is the only solution
for the critical section problem fulfilling all the three requirements. Here the
process shares two variables.

The process P first assigns flag[i] = true. Then it sets the 'turn = j' by asserting that
if any other process wants to enter the critical section, it is possible to do so.When
both processes are attempted to enter at the same time, the 'turn' value will be set to
both i and j at roughly the same time. Here one assignment is last and other will
happen.The process which has to be entered its critical section first will be decided
by the value of 'turn '.
Analysis:
The perfect and final solution for solving mutual exclusion is Dekker’s fifth
version

You might also like