编程论坛's Archiver

love154139 发表于 2008-4-23 17:07

这个互斥算法有什么问题吗

boolean blocked[2];
int turn;
void p(int id)
{
  while(true)
  {
    blocked[id]=true;
    while(trun!=id)
    {
     while(blocked[1-id])
        /*do nothing*/
      turn=id;
     }
     /*critical section*/
     blocked[id]=false;
     /*remainder*/
   }
}

void main()
{
  blocked[0]=false;
  blicked[1]=false;
  trun=0;
  parbegin(p(0),p(1));
}

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.