Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/////////////////////////////// Please don't copy the other answers on the site. They are WRONG. Thank you //////////////////////////////// Java program with two processes (or threads), a producer

///////////////////////////////

Please don't copy the other answers on the site. They are WRONG. Thank you

////////////////////////////////

Java program with two processes (or threads), a producer and a consumer. The producer and consumer will share an integer array with a length of 5 which is a circular buffer. The producer and consumer will also share one or two (your choice) variables to coordinate the placing and removal of items from the circular buffer. The producer process consists of a loop that writes the loop count (a value from 0 to 99) into the shared buffer. On each pass through the loop, before the producer writes into the shared variable, it does a random wait of from one to four seconds (compute a new random wait value on each pass through the loop). The loop is to be executed 100 times. Each time through the loop, it places the loop count into the shared circular buffer if there is an available slot in the buffer, and updates the variable(s) used to control the use of the circular buffer (note that this will have to rap around as the array is only 5 items long). The producer must not clobber any item in the buffer that has not been read by the consumer. If the list is full, the producer must wait for the consumer to remove one or more items from the list before placing the next item in it. This wait is inside the main loop and must have a 1 second sleep in it. The buffer may get full because the producer may be faster than the consumer at times. When the producer puts its last entry into the buffer, it must add one more entry, a -1 which indicates to the consumer that it has completed. The consumer process consists of a loop that reads from the shared circular buffer until the Im done flag (the -1) is detected in the shared buffer indicating that the transfer is complete. On each pass through the loop, before it reads from the shared buffer, the consumer does a random wait of from two to five seconds (compute a new random value on each pass through the loop). It will only read a value from the shared circular buffer if there is one in the buffer it hasnt read. If there is nothing to read, it must wait until there is something to read. When it has to wait it is to write consumer waiting into the output file. When waiting it should do so in a loop that has a 1 second sleep in it and write the consumer waiting message into the file each pass through this wait loop. The consumer must use the variable(s) it shares with the producer to determine which item in the circular buffer is the next item (remember the shared buffer is circular). After the consumer reads a value from the shared circular buffer, it writes the value into an output file and updates the variable(s) it shares with the producer (again note that this has to take into consideration the fact that this index will rap abound) to indicate that this entry is now available for use as the entry has been processed. When it completes, the consumer writes the phrase Consumer done into the output file. Note that the entry just before this should be 99 (the last item removed from the circular buffer). Do not write the -1 into the output buffer. Zip your code file(s), a copy of the output file from your run, and your observations file together and put the zip file into the Dropbox for the 3rd assignment. Your observations for the assignment: What if anything did you learn doing this assignment? Roughly how long (in hours) did the assignment take? Put comments at the top of your program with your name, the date, the assignment number, and a brief description of the program. I also want to see comments within the program. The first items in your data file and observations file must be your name and the assignment number (have your program output this information into your output file).

Note that your output file will almost certainly have some waits in it at RANDOM places if it is working correctly. Run it twice and the output should be slightly different, that is the waits should be in different places. The output might look something like this: John Smith Operating Systems Assignment #3 0 Consumer waiting 1 2 3 4 Consumer waiting Consumer waiting 5 6 7 8 9 10 11 Consumer waiting 12 13 14 15 ... 96 97 98 99 Consumer Done

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions

Question

=+4 Develop and deliver the CCT program.

Answered: 1 week ago

Question

=+5 Evaluate whether the CCT program was effective.

Answered: 1 week ago

Question

=+Identify the type of global assignment for which CCT is needed.

Answered: 1 week ago