Petersons algorithm doubt

17 views
Skip to first unread message

Rahul Shah

unread,
Feb 26, 2012, 8:24:36 PM2/26/12
to asu-cse-430
Hi professor,

I did not understand why the Peterson's algorithm cannot be used for n
processes.

Suppose I consider 3 processes and the

flag[0]=1;
flag[1]=1;
flag[2]=1;
turn=1;
While((flag[1]==1&&turn==1)OR
While((flag[1]==1&&turn==0)OR
While((flag[1]==1&&turn==1)OR
(flag[2]==1&&turn==2))
(flag[2]==1&&turn==2))
(flag[0]==1&&turn==0))


CRITICAL SECTION CRITICAL
SECTION CRITICAL
SECTION

flag[0]=0;
flag[1]=0;
flag[2]=0;


Can you just tell me the scenario where this will not work. I am not
able to figure it out.

Thanks,
Rahul

Partha Dasgupta

unread,
Feb 26, 2012, 11:20:22 PM2/26/12
to asu-c...@googlegroups.com
There is something wrong, semantically and/or typo in this section. Fix it, indent it properly so that I can interpret it and I will try to see why it does not work.

While((flag[1]==1&&turn==1)OR

While((flag[1]==1&&turn==0)OR
While((flag[1]==1&&turn==1)OR
(flag[2]==1&&turn==2))
(flag[2]==1&&turn==2))
(flag[0]==1&&turn==0))




--
You received this message because you are subscribed to the Google Groups "asu-cse-430" group.
To post to this group, send email to asu-c...@googlegroups.com.
To unsubscribe from this group, send email to asu-cse-430...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/asu-cse-430?hl=en.




--
Partha Dasgupta,
School of Computing Informatics, Arizona State University
EMail: par...@asu.edu
http://cactus.eas.asu.edu/partha

Rahul Shah

unread,
Feb 27, 2012, 5:26:34 PM2/27/12
to asu-cse-430
oh. I did not see this. Sorry for that. Here's my question


//Process 0
flag[0]=1;
turn=1;
While((flag[1]==1&&turn==1)OR (flag[2]==1&&turn==2))

CRITICAL SECTION

flag[0]=0;

//Process 1
flag[1]=1;
turn = 2;

While((flag[0]==1&&turn==0)OR (flag[2]==1&&turn==2))

CRITICAL SECTION
flag[1]=0;

//Process 2
flag[2]=1;
turn = 0;

While((flag[0]==1&&turn==0)OR (flag[1]==1&&turn==1))

CRITICAL SECTION
flag[2]=0;

Regards,
Rahul Shah

Partha

unread,
Feb 27, 2012, 6:02:02 PM2/27/12
to asu-cse-430
Does not work. Should I tell you why?

OK a short description and you should try to work out the details.

0 and 1 try to get in, but 1 gets in 0 gets stuck. Then 2 tries to get
in, enabling 0 and letting 0 go through, and now we have 2 processes
in the CS.

Rahul Shah

unread,
Feb 28, 2012, 12:30:30 AM2/28/12
to asu-cse-430
Ok. That means any other process can change the turn variable when
some process is in the critical section. It is not locked.
Reply all
Reply to author
Forward
0 new messages