I was reading about implementation of producer-consumer problem with one producer and one consumer. Looking at this paragraph I see the implementation where shared resource access is not synchronized and producer and consumer can modify shared resource leading to its inconsistent state.semaphore fillCount = 0; // items producedsemaphore emptyCount = BUFFER_SIZE; // remaining spaceprocedure producer() {    while (true) {        item = produceItem();        down(emptyCount);        putItemIntoBuffer(item);        up(fillCount);    }}procedure consumer() {    while (true) {        down(fillCount);        item = removeItemFromBuffer();        up(emptyCount);        consumeItem(item);    }}But the following description says:The solution above works fine when there is only one producer and consumer.But when emptyCount and fillCount are let's say 5 (buffer size is 10), then producer and consumer will simultaneously get access to shared resource and modify underlying collection so for me the solution above does not work fine even if there is only one producer and consumer. Is it the right assumption and a quoted description is wrong?
One producer and one consumer vs inconsistent shared resource state
algorithms;concurrency;parallelism;parallel programming