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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started