2015 the computer real topic big problem signal Volume process synchronization problem

Source: Internet
Author: User
Tags semaphore

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.