How Semaphores Work
The semaphore contains a number, s, which starts at 1
When s is 1, the critical section is empty; when s is 0, the CS is full
sem::P() { sem::V() {
while(s <= 0); s++;
s--; }
}
Test and decrement in P() are atomic; increment in V() is atomic
Previous slide
Next slide
Back to first slide
View graphic version