Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code to accomplish the following. Let the two processes alternate on the CPU. Let the producer process attempt to execute 4 iterations of the


Write code to accomplish the following. Let the two processes alternate on the CPU. Let the producer process attempt to execute 4 iterations of the outer while loop, while the consumer attempts three iterations. Print the value of the shared variables (in, out, counter) after each iteration of the processes. Show the items in the buffer and their location. Clearly indicate which process is the producer and which is the consumer.

 

PLease write code in java programming language 

image



Shared data #define BUF_SIZE 10 typedef struct { //int a; //char x; } item; item buffer[BUF_SIZE]; int in = 0; int out = 0; counter = 0; Consumer Remove() while (true) { while (counter 0) //add code to count the number of times the looping takes place and prints that value. ; // do nothing (just keep looping) // remove an item from the buffer nextConsumed buffer[out]; //write a null value to location out out = (out + 1)% BUF_SIZE; counter--; //add code here to show on the same line, the two variables contained in the variable item. Eg (21, C) Each item must be printed on a separate line. } Producer insert() while (true) { /* Produce an item */ while (counter == BUF_SIZE) //add code to count the number of times the looping takes place and prints that value. ; // do nothing (keep looping) buffer[in] = nextProduced(); in = (in+1)% BUF_SIZE; counter++ } item nextProduce(){ Assigns to each item produced a different value to the variables a and x and return the item. }

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

Computer Architecture A Quantitative Approach

Authors: John L. Hennessy, David A. Patterson

4th edition

123704901, 978-0123704900

More Books

Students also viewed these Programming questions

Question

=+a) Student ratings of an instructor on a 5 point Likert scale.

Answered: 1 week ago