小弟這個問題...已經PO在奇摩知識快1個月了...
都沒人回應..希望站上有高手可以幫忙...
題目如下: Find a counterexample that demonstrates that this solution is incorrect
(請找出下列程式中的錯誤)
Concider the following program:
1 bollean block[2];
2 in turn;
3 void P(int id){
4 while(true){
5 blocked[id]=true;
6 while(turn!=id){
7 while(Blocked[1-id])
8 ;
9 turn=id;
10 }
11 /* critical section*/
12 blocked[id]=false;
13 /* remainder*/
14 }
15 }
16 void manin(){
17 blocked[0]false;
18 blocked[1]false;
19 turn=0;
20 parbegin(P(0),P(1));
21 }
這邊沒點數可給...只能先給各位高手說聲謝謝!!
in turn; // error:in not defined maybe 'int'
void P(int id)
{
while(true) // forever loop ?
{
blocked[id]=true;
while(turn!=id)
{
while(Blocked[1-id]) ;
turn=id;
}
/* critical section*/
blocked[id]=false;
/* remainder*/
}
}
void manin() //?? main?
{
blocked[0]false; //wherw is '='
blocked[1]false; //wherw is '='
turn=0;
parbegin(P(0),P(1)); //?? parbegin not defined
}
m01是很有人情味的地方,我用人工compiler的...
不過....如果這是題目,那出題的人很可能有問題@@
內文搜尋

X