subject

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 4, when Producer and Consumer concurrently execute, what are the possible values of ‘’counter", please give an example for each value, point out which value is the right one and analysis the reasons for the wrong values.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 10:00
You need a reliable network for about twenty-five computers that will be distributed across a large building. it is important that the network be relatively cheap. which topology should you use?
Answers: 1
question
Computers and Technology, 22.06.2019 10:00
What is a society that has moved to the internet rather than relying on physical media called
Answers: 2
question
Computers and Technology, 22.06.2019 17:00
Your computer running windows 10 is doing some very strange things with the operating system. you are fairly certain it is not a hardware issue. you need to try to get further insight into what is going on within the operating system. which tool would be best suited for this?
Answers: 2
question
Computers and Technology, 22.06.2019 21:30
After you clean an engine with hot water spray, it seems to stall; when it doesn't stall, it's idling noisily. technician a says to check for loose bolts on the flex plate near the torque converter. technician b says to wipe down the spark plug wires and the distributor cap. who is correct? a. technician a b. both technicians a and b c. technician b
Answers: 1
You know the right answer?
Here are the codes for producer and consumer problems.

Producer:

while (true...
Questions
question
Mathematics, 03.10.2020 01:01
question
Mathematics, 03.10.2020 01:01
question
Mathematics, 03.10.2020 01:01
question
Mathematics, 03.10.2020 01:01
question
Mathematics, 03.10.2020 01:01
question
Mathematics, 03.10.2020 01:01
Questions on the website: 13722359