Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the Producer-Consumer problem. The maximum queue size is 11. Consider t

ID: 3822916 • Letter: C

Question

Consider the Producer-Consumer problem.
The maximum queue size is 11.
Consider the following solution. Is this code correct? (YES or NO).
If the answer is NO, give a detailed scenario to exhibit the
incorrect behavior. If answer in YES, give an explanation in
50 words or less.

****HINT: The sequential computing aspect of the code is correct. You have to think
**** of problems arising from CONCURRENT PROCESSES.



semaphore s=1, s1=1, s2=1;
itemtype A[11]: //array index is 0…10
int n=0; /* no. of items in the queue.
n==0 means queue is empty.
n!=0 means queue is non-empty and the
items are in positions
f, (f+1) mod 11, (f+2) mod 11, ... n items.
We will try to make sure that (-1) < n < 12. */

int f=0; /* We will try to make sure that (-1) < f < 11.
*/

bool qempty(); bool qfull()
{ return (n==0);} {return (n==11);}


void enque(item, r) itemtype deque(){
{ A[r]=item; itemtype item;
n= n+1;} item= A[f];
f= f+1;
if (f==11) then f= 0;
n= n-1;
return item;}
Code of a Producer Code of a Consumer
------------------ ------------------

local var item; int r; local var item;

L1: produce(item);
L2: P(s1); M1: P(s2);
L3: while (qfull()); M2: while (qempty());
(*loop ends here*) (*loop ends here*)
r= f+n;
if (r>10) r=r-11;
//r is index of last
//item in queue.
P(s); P(s);
L4: enque(item, r); M3: deque(item);
V(s); V(s);

L5: V(s1) M4: V(s2);
L6: go to L1 M5: consume(item);
M6: go to M1

Consider the Producer-Consumer problem The maximum queue size is 11 Consider the following soluton. sthis code correct? YES or NO). Mthe answer NO.give a detailed scenario 10exhibithe incorrect behavior, fanswerin YES,give an explanaton in 500 words or less. """HINT The sequential computing aspectofthe code is correct, You have to think of problems arising from CONCURRENTPROCESSES semaphore s-1, s1 1. s2-1: itemtype AN111Aarrayindexis0...10 intna0./ no. ofitems inthe queue n means queue is empty. n! means queue is non-empty and he iems are in posbons f(-1) mod 11. +2) mod 11 We wilty to make sure that -10

Explanation / Answer

Answer : Yes

Here, the Producer class is a thread which constantly produces objects and put them into the queue. In practice, we should specify condition to exit the loop, such as closing/shutdown the program or a maximum number of objects reached.

The Consumer class is another thread which constantly takes objects from the queue to process. In practice, we should specify condition to stop this thread by checking the queue for a special object.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote