562 views
0 votes
0 votes

I am confused in understanding the complete flow of producer-consumer problem in following schenerio.

Let currently buffer in empty and there is no data in there,and let some how consumer starts executing and will make F = -1, and go to sleep. Now Producer comes into execution inserts data into buffer comes out of critical section and will finally makes F=0 and wakes up consumer.

Now just before producer executing again, consumer start executing from line where it goes to sleep i.e wait(F),  i mean now F is 0 again means consumer will perform wait(F) goes to sleep again isn’t.

Note:- F is the counting semaphore helping consumer to determine if there is even a single buffer full to consume from it.

1 Answer

Best answer
1 votes
1 votes

Let currently buffer in empty and there is no data in there,and let some how consumer starts executing and will make F = -1, and go to sleep. Now Producer comes into execution inserts data into buffer comes out of critical section and will finally makes F=0 and wakes up consumer. // Wrong statement

Even consumer will start executing when full=0, then it will wait/sleep till full>0. After full>0 then only consumer’s wait(full) can decrement the value of full and proceed further.

So basically you are confused with the working of “Wait(full)”. Wait will not decrement value in the consumer until full value is greater than 0.

 

selected by

Related questions

0 votes
0 votes
1 answer
4