The Gateway to Computer Science Excellence
0 votes
605 views

in Operating System by Junior (873 points) | 605 views

2 Answers

0 votes

There is no ME, right? Before entering CS,

turn = i would be executed. 

That means other process can enter CS as well. 

by Junior (617 points)
0
but in CS, turn = i for process i, which means other process will be waiting in the while loop.
0
ME is there.

Isn't the solution incorrect because progress is no there? Once the processes set their flags to true, deadlock will occur.
0

This is clearly peterson's algorithm without explicit condition to check for turn.

 while (flag[1] && turn == 1)
         {
             // busy wait
         }

You see , in given code turn == 1  && flag is not checked in single operation (atomic ).

I'm having hard time believing we'd have ME there.

Consider , after busy wait (do no_op loop) , there was context switch and then P0,P1 might enter CS at same time.

Since Flag is toggled in Remainder , progress is there.

https://en.wikipedia.org/wiki/Peterson%27s_algorithm

0 votes
This is a correct solution to the critical section problem.

Reason:-

satisfies  mutual exclusion :-value of turn can be either i or j at the same time so any one process can be in cs.

satisfies progress-after execution of each process its flag is set to false (see in the exit section) .as this flag goes to f other waiting process whose flag value is 1(process interested to enter cs) will enter the cs as while loop condition satisfies in this sitiuation.

bounded waiting-after completing its execuion in cs its flag is set to false which allow other process to enter the cs .the same process cant be executed again and again indefinetly if other process is ready and waiting.
by Active (2.3k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,391 answers
198,589 comments
105,442 users