Operating sys : In the following producer and consumer problem using semaphores, explain with an example (semaphore values), how a producer sends a signal to a consumer, so that the consumer does not have to check the buffer all the time. /*program, Producer/Consumer */ semaphore n = 0; /* no of items in the buffer */ semaphore s = 1; /* ME semaphore */ void Producer () { while(TRUE) { produce(); wait(s); append(); signal(s); signal(n); } } void Consumer () { while(TRUE) { wait(n); wait(s); take(); signal(s); consume(); } }
Operating sys :
In the following producer and consumer problem using semaphores, explain with an example (semaphore values), how a producer sends a signal to a consumer, so that the consumer does not have to check the buffer all the time.
/*program, Producer/Consumer */
semaphore n = 0; /* no of items in the buffer */
semaphore s = 1; /* ME semaphore */
void Producer ()
{
while(TRUE)
{
produce();
wait(s);
append();
signal(s);
signal(n);
}
}
void Consumer ()
{
while(TRUE)
{
wait(n);
wait(s);
take();
signal(s);
consume();
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps