producent-konsument zaczerpnięte z Wikipedia:producent-konsument z sempahores
semaphore mutex = 1
semaphore fillCount = 0
semaphore emptyCount = BUFFER_SIZE
procedure producer() {
while (true) {
item = produceItem()
down(emptyCount)
down(mutex)
putItemIntoBuffer(item)
up(mutex)
up(fillCount)
}
up(fillCount) //the consumer may not finish before the producer.
}
procedure consumer() {
while (true) {
down(fillCount)
down(mutex)
item = removeItemFromBuffer()
up(mutex)
up(emptyCount)
consumeItem(item)
}
}
Moje pytanie - dlaczego producent ma up(fillCount) //the consumer may not finish before the producer
po pętli while. Kiedy program dotrze do celu i dlaczego jest potrzebny?