S
Solo.Wolve
while(TRUE){
while (turn != 0) /* Should here be a semicolon ( ; ) to make while a
NULL repetition? */
critical_region();
turn = 1;
noncritical_region();
}
/* (a) PROCESS 0 */
while(TRUE){
while (turn != 1) /* Should here be a semicolon ( ; ) to make while a
NULL repetition? */
critical_region();
turn = 0 ;
noncritical_region();
}
/* (b) PROCESS 1*/
Aside:
Initially, process 0 inspects turn, find it to be 0, and enter the
critical region.Process 1 also finds it to be 0 and therefore sits in a
tight loop continually test to see when it becomes 1.
End Aside.
My problem: if there is no semicolon following the inner while , then
(a) process 0 , In the code, when the variable turn set to 0 initially,
while( turn != 0) is false, so the following line critical_region is
skipped over !!
then it will entry noncritical_region.
The same ,(b)Process 1
as turn set to 0 inititally, while (turn != 1) is true.
it should enter the while loop,execute critical_region?
It Contradicts with the book!!!
Please look at it and help me,Thank you.
while (turn != 0) /* Should here be a semicolon ( ; ) to make while a
NULL repetition? */
critical_region();
turn = 1;
noncritical_region();
}
/* (a) PROCESS 0 */
while(TRUE){
while (turn != 1) /* Should here be a semicolon ( ; ) to make while a
NULL repetition? */
critical_region();
turn = 0 ;
noncritical_region();
}
/* (b) PROCESS 1*/
Aside:
Initially, process 0 inspects turn, find it to be 0, and enter the
critical region.Process 1 also finds it to be 0 and therefore sits in a
tight loop continually test to see when it becomes 1.
End Aside.
My problem: if there is no semicolon following the inner while , then
(a) process 0 , In the code, when the variable turn set to 0 initially,
while( turn != 0) is false, so the following line critical_region is
skipped over !!
then it will entry noncritical_region.
The same ,(b)Process 1
as turn set to 0 inititally, while (turn != 1) is true.
it should enter the while loop,execute critical_region?
It Contradicts with the book!!!
Please look at it and help me,Thank you.