Structure of sem_t and implementation of semaphores
In C programming language why do we need a special sem_t type for defining the semaphore? Couldn't that been an integer?How is sem_t defined? How is the functions sem_post and sem_wait implemented? EDIT:An example implementation like GNU C library will be great.
Semaphores are OS kernel managed objects, so sem_t will be OS-specific, as will be the signal/wait calls since they also necessarily call into the OS kernel.
Usually, the semaphores are implemented by a unit count and a queue for any waiting threads.