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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 01:30, solikhalifeoy3j1r
In deadlock avoidance using banker’s algorithm, what would be the consequence(s) of: (i) a process declaring its maximum need as maximum possible for each resource. in other words, if a resource a has 5 instances, then each process declares its maximum need as 5. (ii) a process declaring its minimum needs as maximum needs. for example, a process may need 2-5 instances of resource a. but it declares its maximum need as 2.
Answers: 3
image
Computers and Technology, 23.06.2019 06:40, euniceyi56
How many nibbles can be stored in a 16-bit word?
Answers: 1
image
Computers and Technology, 24.06.2019 04:30, littledudefromacross
Write and test a python program to find and print the largest number in a set of real (floating point) numbers. the program should first read a single positive integer number from the user, which will be how many numbers to read and search through. after reading in all of the numbers, the largest of the numbers input (not considering the count input) should be printed.
Answers: 1
image
Computers and Technology, 24.06.2019 07:30, Isabellawuzhere
Aproject involves many computing systems working together on disjointed task towards a single goal what form of computing would the project be using
Answers: 3
You know the right answer?
Here are the codes for producer and consumer problems.

Producer:

while (true...

Questions in other subjects:

Konu
History, 26.07.2019 04:00
Konu
History, 26.07.2019 04:00