Write a program to coordinate (synchronize) the processor and the processes.

Synchronization Problem: Suppose a processor can service only one process at any time instant but has a buffer of size 6 associated with it. That is, at most 6 processes can wait for the processor while it is servicing a process. The following happen between the processor and processes:

  • If there are no processes, the processor is idle.
  • If a process arrives in the buffer and the buffer is full, then the process leaves the system and never returns.
  • If the processor is busy but buffer is not full, then the arriving process waits in one of the free spaces in the buffer.
  • If the processor is idle, the process wakes up the processor to get service.

Write a program to coordinate (synchronize) the processor and the processes. You can put the upper limit of stream of processes to 30.

Hints: You could view each process as a separate Java thread. You may construct a new system scenario with a processor for threads to get service. (The processor can be viewed simply as an object having some state value as “busy”, “idle” etc.). You may set the system to have a buffer with 6 places. You can make all places be initially empty. Also, you may set the processor to be idle so that when the first thread comes in, it can wake the processor up. If the processor was busy, then this thread has waited in the buffer. Entering threads will have to wait for the existing threads to be serviced. As far as which waiting thread will get service next is up to the JVM. You should have methods to control the inflow, preferably random, of threads. That is, when a new thread would appear, should be random (threads should not appear in regular pre-defined intervals). Also, the service time should be random (that is, the processor cannot take fixed set amount of time for each thread). You could use thread sleep utility together with random numbers to implement these.

Typical output may look like the following. However, you are free to modify the print statements to show the synchronization. Make sure that your output conveys the same information as the sample output.

Sample output (continued to next page):

ENTERING SYSTEM: Thread [0] entering the system for service.

PROCESSOR IS IDLE: Thread [0] is waking processor up and getting service.

LEAVING SYSTEM: Thread [0] service finished: leaving system.

ENTERING SYSTEM: Thread [1] entering the system for service.

PROCESSOR IS IDLE: Thread [1] is waking processor up and getting service.

ENTERING SYSTEM: Thread [2] entering the system for service.

LEAVING SYSTEM: Thread [1] service finished: leaving system.

PROCESSOR IS BUSY: Thread [2] has waited and now wants service.

ENTERING SYSTEM: Thread [3] entering the system for service.

LEAVING SYSTEM: Thread [2] service finished: leaving system.

PROCESSOR IS BUSY: Thread [3] has waited and now wants service.

ENTERING SYSTEM: Thread [4] entering the system for service.

ENTERING SYSTEM: Thread [5] entering the system for service.

ENTERING SYSTEM: Thread [6] entering the system for service.

ENTERING SYSTEM: Thread [7] entering the system for service.

ENTERING SYSTEM: Thread [8] entering the system for service.

ENTERING SYSTEM: Thread [9] entering the system for service.

ENTERING SYSTEM: Thread [10] entering the system for service.

LEAVING SYSTEM: The buffer is full. Thread [10] is leaving system.

LEAVING SYSTEM: Thread [3] service finished: leaving system.

PROCESSOR IS BUSY: Thread [6] has waited and now wants service. // selected by JVM

ENTERING SYSTEM: Thread [11] entering the system for service.

ENTERING SYSTEM: Thread [12] entering the system for service.

LEAVING SYSTEM: The buffer is full. Thread [12] is leaving system.…

Comments in the header: Each program file should contain the following: course number (CS4345), Semester/Year (Spring 2017), assignment identifier (Program 3), and authors of the program (all members in the group who was involved in the assignment). You may use regular Java comments or Javadoc comments to furnish above information.

 

Submission instruction: Submit your file through BlazeVIEW submission box.

Order from us and get better grades. We are the service you have been looking for.