Multithreaded Programming And Synchronization

Write code to help synchronize a professor and his/her students during office hours. The professor, of course, wants to take a nap if no students are around to ask questions; if there are students who want to ask questions, they must synchronize with each other and with the professor so that

(i) No more than a certain number of students can be in the office at the same time because the office has limited capacity. (ii) Only one person is speaking at a time. (iii) Each student question is answered by the professor. (iv) No student asks another question before the professor is done answering the previous one. (v) Once a student finishes asking all his/her questions, he/she must leave the office to make room for other students waiting outside the professor’s office. You are to provide the following functions: Professor(). This functions starts a thread that runs a loop calling AnswerStart() and AnswerDone(). See below for the specification of these two functions. AnswerStart() blocks when there are no students around. Student(int id). This function creates a thread that represents a new student with identifier id that asks the professor one or more questions (the identifier given to your function can be expected to be greater or equal to zero and the first student’s id is zero). First, each student needs to enter the professor’s office by calling EnterOffice(). If the office is already full, the student must wait. After a student enters the office, he/she loops running the code QuestionStart() and QuestionDone() for the number of questions that he/she wants to ask. The number of questions is determined by calculating (student identifier modulo 4 plus 1). That is, each student can ask between 1 and 4 questions, depending on the id. For example, a student with id 2 asks 3 questions, a student with id 11 asks 4 questions and a student with id 4 asks a single question. Once the student has got the answer for all his/her questions, he/she must call LeaveOffice(). As a result, another student waiting on EnterOffice() may be able to proceed. AnswerStart(). The professor starts to answer a question of a student. Print … Professor starts to answer question for student x. AnswerDone(). The professor is done answering a question of a student. Print … Professor is done with answer for student x. EnterOffice(). It is the student’s turn to enter the professor’s office to ask questions. Print … Student x enters the office. LeaveOffice(). The student has no more questions to ask, so he/she leaves the professor’s office. Print … Student x leaves the office. QuestionStart(). It is the turn of the student to ask his/her next question. Print … Student x asks a question. Wait to print out the message until it is really that student’s turn. QuestionDone().

Don't use plagiarized sources. Get Your Custom Essay on
Multithreaded Programming And Synchronization
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

The student is satisfied with the answer to his most recent question. Print … Student x is satisfied. Since professor considers it rude for a student not to wait for an answer, QuestionDone() should not print anything until the professor has finished answering the question. A student can ask only one question each time. i.e., a student should not expect to ask all his/her questions in a contiguous batch. In other words, once a student gets the answer to one of his/her questions, he/she may have to wait for the next turn if another student starts to ask a question before he/she does. In the above list, x is a placeholder for the student identifier. Your program must accept one command line parameter that represents the total number of students coming to the professor’s office, and a second command line parameter that represents the capacity of the professor’s office (i.e., how many students can be in the office at the same time). For simplicity, you can assume that the Student threads are created at the ascending order of their identifiers. Your program must validate the command line parameters to make sure that they are numeric values. Your program must be able to run properly with any reasonable number of students (e.g., 200) and room capacity (e.g., 8, 20, 50). Your program must show randomness of events. For example, groups of students entering office at various points in the simulation. Your program must reach a completion state and terminate gracefully. A proper message should be output to indicate end of simulation, One acceptable output of your program is (assuming 3 students and a room capacity of 2):

Grand Paper Writers
Order NOW For A 10% Discount!
Pages (550 words)
Approximate price: -

Our Advantages

Plagiarism Free Papers

All papers are written by the best professional writers to ensure 100% originality. We always provide plagiarism reports whenever we deliver completed papers.

Free Revisions

All papers by Grand Paper Writers are completed and submitted on time. This timely delivery of papers gives you time to go through the paper before the official deadline.

Title-page

As an additional service, we will provide a title page that precedes the contents of your paper. Here, you will provide your personal details.

Bibliography

We also ensure that we provide an extra page for the references or bibliographies following referencing rules.

Originality & Security

At Grandpaperwriters.com, we guarantee students for the provision of security and original work. All your personal information is handled with confidentiality and is not shared with third parties. Additionally, we ensure that we provide original content with accompanying plagiarism reports to show originality.

24/7 Customer Support

Our customer support team is always available 24/7 to provide instant responses to any queries raised by students.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Grandpaperwriters.com has the best professional essay writers for quality services.

Pricing

Flexible Pricing

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Communication

Admission Help & Client-Writer Contact

Grandpaperwriters.com provides an interactive portal where students can communicate directly to their writers.

Deadlines

Paper Submission

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Reviews

Customer Feedback

Grandpaperwriters.com appreciates feedback from our clients to help us improve the delivery of essay writing services. As such, we are constantly changing our policies to ensure maximum customer and writer satisfaction.