Question: 1. Here are the codes for producer and consumer problems Producer: while (true) { /* produce an item in next produced */ while (counter ==

1. Here are the codes for producer and consumer problems

Producer:

while (true) { /* produce an item in next produced */

while (counter == BUFFER_SIZE) ;

/* do nothing */

buffer[in] = next_produced;

in = (in + 1) % BUFFER_SIZE;

counter++;

}

Consumer:

while (true) {

while (counter == 0)

; /* do nothing */

next_consumed = buffer[out];

out = (out + 1) % BUFFER_SIZE; counter--;

/* consume the item in next consumed */

}

counter++ could be implemented by Producer as register1 = counter register1 = register1 + 1 counter = register1

counter-- could be implemented by Consumer as register2 = counter register2 = register2 - 1 counter = register2

If we set the current value of counter as 7, when Producer and Consumer concurrently execute one time, what are the possible values of counter, please give an example for each values.

Answer:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!