You are on page 1of 8

Presentation

on
Critical Section Problem

+
The Critical-Section Problem

n processes competing to use some shared data.

No assumptions may be made about speeds or the


number of CPUs.

Each process has a code segment, called Critical


Section (CS), in which the shared data is accessed.

Problem ensure that when one process is executing in


its CS, no other process
is allowed to execute in its CS.

Solution to Critical-Section
Problem

There are 3 requirements that must stand for a correct


solution

1.
2.
3.

Mutual Exclusion
Progress
Bounded Waiting

.The requirements can be achieved by using


Peterson Algorithm

+
Peterson Algorithm
do{

do{

flag[i] = true;
turn = j;

flag[j] = true;
turn = i;

while(flag[j] && turn==j)


critical section;
flag[i] = false;
remainder section;
} while(true);

while(flag[i] && turn==i)


critical section;

flag[j] = false;
remainder section;
} while(true);

+
Mutual Exclusion
Occurs

when two or more processes are ready and


allowed to execute at its critical section
concurrently

Turn will be set to each process at roughly same


time but lasts for only one.

There

will be a delay but the other process occurs


immediately after that

During

the CS execution of one from two


simultaneous process, the other process ready flag
is being false

+
Progress
If

no process is in critical section, any


process that request entry the critical section
must be permitted to entry.

If

only one process wants to enter, it should


be able to.

If two or more want to enter, one of them


should succeed

+
The bounded waiting
requirement
the

prevention for both process depends


on flag[j]==true && turn==j and
flag[i]==true && turn==i

turn->

deciding factor, common

variable.
Process

that shows courtesy last, loses in


stalemate

process changes its flag status to false


after critical operation.

Outermost

loop resets flag condition.

Wait.your
turns up.
Let the next
process enter
its critical
section.

THANK
YOU

You might also like