Question
I was assigned a homework in Java programming language to create a concurrent program that runs on thread interfaces. Here is the exact specification: a)
I was assigned a homework in Java programming language to create a concurrent program that runs on thread interfaces. Here is the exact specification:
a) Printer Process
The maximum number of sheets of paper the printer can contain, is 3. All documents take just one sheet of paper to print.
Its behaviour is as follows:
- It is initialized with 3 sheets of paper.
- Provided the printer has at least one sheet of paper left, it can be used to print a document.
- To print a document:
(i) a user must take mutually exclusive control of the printer,
(ii) the document is then printed,
(iii) the user releases mutually exclusive control of the printer,
(iv) the number of sheets of paper in the printer is reduced by 1 & the
printer is then ready to print another document.
- When the printer has run out of paper, a user cannot use it to print a document.
- When the printer has run out of paper, the technician can then refill it with the maximum amount of paper, i.e. 3 sheets.
The printer must not suffer from "data corruption & interference". That is each user must have mutually exclusive access to the printer while it is being used and it must keep a correct count of the sheets of paper.
(b) Student Process
All of the documents the student wants to print, are short & take only one sheet of paper to print. A student's behaviour is as follows:
- It is initialized with the number of documents it is to print.
- For each document:
(i) it takes mutually exclusive control of the printer,
(ii) prints the document &
(iii) then releases control of the printer.
- When it has finished printing all its documents it terminates.
(c) Technician Process
Its behaviour is as follows:
- Repeatedly, check if the printer is out of paper.
- When the printer is out of paper, it refills the printer with the maximum number of sheets it can take, i.e. 3.
(d) Printing System
This combines instances of the above processes in parallel. It must ensure mutual exclusive access is maintained for use of the printer.
This combines the following four processes in parallel:
- One student process that is to print 3 documents.
- One student process that is to print 2 documents.
- One technician process that refills the printer with 3 sheets of paper.
- One printer process that can hold up to 3 sheets of paper.
I was wondering how to approach this problem as I come from c++/c# background and I haven't worked with Java at all. Is there maybe any pseudo code someone could help me with to sort this problem out and how to actually design the thread interface?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started