DOWN OPERATION (SEMAPHORE) if r > 0; then r = r - 1; else SLEEP(process);
Lets look at an example of semaphores. In figure A, there are three semaphores. S1 which has a value of zero. Process 1 is blocked on S1. S2 has a value of three, meaning three more processes may execute a down operation on S2 without being put to sleep. S3 has a value of zero, and has two sleeping processes, P4 and P5.
Low lets look at what happens when a process executes an UP on S1. Process P1 is activated by the UP operation. It executes a DOWN on S1 and enters its critical section. The state of the semaphores after these actions is shown in figure B.