hahaha, to take the examination of the topic to test you, see what you do come out not, who let me is the test computer graduate of the package, I hope to join the research and development team, after all, I want to be a technology home.
45. A, b two people through the mailbox debate, each person from their own mailbox to obtain the other side of the problem. Put the answer and the new question to the other party into a mail in each other's mailbox, set A's box to put up m e-mail, B's mailbox to put up n mail. There are x messages (0<x<m) in the mailbox at the beginning of a. There are Y (0<y<n) in B. The number of messages in the debate was reduced by 1 per message.
A, b Two-person operation process:
Code Begin
a{
while (TRUE) {
Remove an email from A's mailbox;
Answer the question and ask a new question;
Put the new mail in B's mailbox;
}
}
b{
while (TRUE) {
Remove an email from B's mailbox;
Answer the question and ask a new question;
Put the new mail into A's mailbox;
}
}
Code End
When the mailbox is not empty, the speaker can pick up the mail from the mailbox or wait.
When the mailbox is not satisfied, the speaker can put the new mail in the mailbox, otherwise wait.
Add the necessary semaphores and P, V (or wait, signed) operations to synchronize the above process, require the complete process to be written, and explain the meaning and initial value of the semaphore.
"Reference Answer"
Semaphore mutexa=1;
Semaphore mutexb=1;
Semaphore emptya=m;
Semaphore emptyb=n;
Semaphore fulla=0;
Semaphore fullb=0;
Code Begin
a{
while (TRUE) {
P (Fulla);
P (Mutexa)
Get a mail from A_mailbox;
V (Mutexa);
V (Fulla);
Answer the question and raise a question;
P (EMPTYB);
P (MUTEXB)
Send the mail to B;
V (MUTEXB);
V (EMPTYB);
}
}
b{
while (TRUE) {
P (FULLB);
P (MUTEXB)
Get a mail from B_mailbox;
V (MUTEXB);
V (FULLB);
Answer the question and raise a question;
P (Emptya);
P (Mutexa)
Send the mail to A;
V (Mutexa);
V (Emptya);
}
}
Code End
"Examining the Knowledge points" investigates the problem of using the signal volume process synchronization.
<p><a href= "http://www.kyjxy.com/fushi/zhinan/" > Postgraduate exam english listening </A></P>
<p><a href= "http://www.kyjxy.com/yingyu/zhenti/" > Postgraduate examination of English real topics </A></P>
<p><a href= "http://www.kyjxy.com/yuanxiao/zhengce/" > Postgraduate Professional Catalogue </A></P>
2015 the computer real topic big problem signal Volume process synchronization problem