As an abstract data type a semaphore sconsists of:
- an integer value (private)
- a list of threads waiting (private)
- sem_init(&s) (public) initialize the integer value (>= 0)
- sem_wait(&s) (public) try to decrement the integer; possibly causing the calling thread to block
- sem_post(&s) (public) increment and possibly unblocking one or the waiting threads.
The functions should be atomic. That is, If 2 or more threads attempt to call either of these functions concurrently, the calls will execute one after the other in some order, but execution will not be interleaved with only a part of a function being executed by one thread before another thread starts executing one of the functions.