Need some assistance with the below, can anyone offer some advice on how to solv
ID: 3883014 • Letter: N
Question
Need some assistance with the below, can anyone offer some advice on how to solve this?
Study carefully the following code: #define BUFFER_SIZE X typedef struct { } // Producer while (1) { while (((in + 1) % BUFFER_SIZE) = = out.);// do nothing buffer [in] = nextProduced: in = (in + 1) % BUFFER_SIZE } // Consumer while (1) { while (in = = out): nextConsumed = buffer [out]: out = (out + 1) % BUFFER_SIZE } a. State and explain the effect of assigning a value of 1 to BUFFER_SIZE? b. Suppose your friend rewrote the producer code and called it "MyVersionOfProducer". However, after carefully studying it, you found a problem/issue in this version. Explain the issue with an example. // Producer while (1) { while (in = = out): // do nothing buffer [in] = nextProduced: in = (in + 1) % BUFFER_SIZE }Explanation / Answer
1. the value 1 is assignes to the buffer time because buffer time is the time used between two procedures so we keep it as 1 so that the execution goes smoth between producer and customer.try to overcome this deficiency by introducing a counter variable, as shown in the following code segments:
while(1){
while(counter==BUFFER_SIZE){
buffer[in]=nextProduced;
in =in+1 % BUFFER_SIZE;
counter++;
}
}
2.the issue can be because of the value of in will be unavailable and while the producer is running .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.