0
cond 변수와 세마포어를 사용하여 생산자 소비자 문제 구현을 비교하려고합니다.sem_wait에서 while 루프가 필요하지 않은 이유는 무엇입니까?
구현하여 COND 변수 :
acquire(m); // Acquire this monitor's lock.
while (!p) { // While the condition/predicate/assertion that we are waiting for is not true...
wait(m, cv); // Wait on this monitor's lock and condition variable.
}
// ... Critical section of code goes here ...
signal(cv2); -- OR -- notifyAll(cv2); // cv2 might be the same as cv or different.
release(m);
구현하여 세마포어 :
produce:
P(emptyCount)
P(useQueue)
putItemIntoQueue(item)
V(useQueue)
V(fullCount)
이유 세마포어 구현 COND 변수 구현 루프가 같은 상태를 확인하는 동안 사용되지 않는다.?
while (!p) { // While the condition/predicate/assertion that we are waiting for is not true...
wait(m, cv); // Wait on this monitor's lock and condition variable.
}
Why do you need a while loop while waiting for a condition variable