注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
Q2. The two processes P1 and P2 which are accessing the shared variables A and B are protected by two binary semaphores Na and Nb respectively and both initialized to 1. Let X and Y be the usual semaphore operators. X decrements the semaphore value and Y increments the semaphore value. The code of P1 and P2 are given below:
P1
While true do {
M1: ……………..
M2: ………………
A = A+1;
B = B-1;
Y (Na);
Y (Nb);
P2
While true do {
M3: ……………..
M4: ………………
B = B+1;
A = B-1;
Y (Nb);
Y (Na);
What should be the correct operators at M1, M2, M3 and M4 in order to avoid deadlock condition?
1. X(Na), X(Nb), X(Nb), X(Na)
2. X(Na), X(Nb), X(Na), X(Nb)
3. X(Nb), X(Na), X(Nb), X(Na)
4. X(Nb), X(Na), X(Na), X(Na)
View Answer / Hide Answer
ANSWER: 2. X(Na), X(Nb), X(Na), X(Nb)
为什么answer 3不可以要求,原理不是一样的吗~ |