Categorygithub.com/adrian-lin-1-0-0/go-studyosprocess_synchronizationsemaphoreproducer-consumer_problem
package
0.0.0-20241120161739-ebe831b73250
Repository: https://github.com/adrian-lin-1-0-0/go-study.git
Documentation: pkg.go.dev
# README
Producter-Consumer Problem
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);
}
}
procedure consumer() {
while (true) {
down(fillCount);
down(mutex);
item = removeItemFromBuffer();
up(mutex);
up(emptyCount);
consumeItem(item);
}
}