Semaphore wait() and signal()
I think it's an inaccuracy in your source. Atomic
for the wait()
operation means each iteration of it is atomic
, meaning S--
is performed without interruption, but the whole operation is interruptible after each completion of S--
inside the while
loop.
I don't think, keeping an infinite while loop inside the wait() operation is wise. I would go for Stallings' example;
void semWait(semaphore s){
s.count--;
if(s.count<0)
*place this process in s.queue and block this process
}