There are several ways to implement the semaphore abstract data type.
Looking at one possible way can help elaborate the missing details from the abstract description.
- The integer can be initialzed to any value >= 0.
- sem_wait:
- first decrement the integer
- if the value is now < 0, the calling thread is blocked and placed on the wait list for this semaphore
- return
- sem_post:
- first increment the integer
- if the value is now <= 0, the wait list is not empty. Unblock one of the threads (presumably first in, first out)
- return