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, 22.06.2019 11:00, paigesyring
How does a policy manual an organization? a. it boost productivity. b. it create awareness in employees about the organization’s values. c. it employees achieve targets. d. it safeguards the organization from liabilities.
Answers: 1
image
Computers and Technology, 22.06.2019 19:10, hgdthbgjnb83661
What a backup plan that you have created in a event you encounter a situation
Answers: 2
image
Computers and Technology, 23.06.2019 01:30, bri2728
Jason works as an accountant in a department store. he needs to keep a daily record of all the invoices issued by the store. which file naming convention would him the most? a)give the file a unique name b)name the file in yymmdd format c)use descriptive name while naming the files d)use capital letters while naming the file
Answers: 3
image
Computers and Technology, 23.06.2019 05:20, reeeeeee32
What did creator markus “notch" persson initially call his game
Answers: 1
You know the right answer?
Here are the codes for producer and consumer problems.

Producer:

while (true...

Questions in other subjects:

Konu
Computers and Technology, 06.03.2022 14:00
Konu
English, 06.03.2022 14:00