Modern Operating System P 105, I can't understand the code

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.
 
E

epsylon

On 13 Dec 2006 07:37:37 -0800, "Solo.Wolve" <[email protected]>
wrote:

[...]

Actually, if you read *carefully* the book, there is a semicolon, its
written like that :
while (turn != 0) /* loop */ ;
^ here it is, after the comment.
 
S

Solo.Wolve

epsylon said:
On 13 Dec 2006 07:37:37 -0800, "Solo.Wolve" <[email protected]>
wrote:

[...]

Actually, if you read *carefully* the book, there is a semicolon, its
written like that :
while (turn != 0) /* loop */ ;
^ here it is, after the comment.

I saw it actually.
I mean, the loop is just an empty loop, Or it contains the following
stetement,
critical_region?
If it's not empty loop, I don't understand.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top