Hello
Shared Memory Solution
# difine BUFFER_SIZE 10 typedef struct{ ..... } item; item buffer[BUFFER_SIZE]; int in=0; int out=0;
this code for producer
while (true) { /* produce an item */ while (((in=(in+1)%BUFFER SIZE count)==out); /* do nothing -- no free buffers */ buffer[in]= item; in=(in+1)%BUFFER SIZE ; }
this code for consumer
while (true){ while (in==out) //do nothing -- nothing to consume //remove an item from the buffer item = buffer[out]; out =(out+1)% BUFFER SIZE ; return item ; }
this solution is correct , but can only use BUFFER_SIZE-1elements
now i want Solution to this question
Modify the producer , consumer code for having n element for the buffer??