sem_init - initialize an unnamed semaphore
#include <semaphore.h>
sem_init() is used to initialize the unnamed semaphore, referred to by sem, to value. This semaphore may be used in subsequent calls to sem_wait(), sem_trywait(), sem_post(), and sem_destroy(). This semaphore remains usable until the semaphore is destroyed.
If pshared is non-zero, then the semaphore is sharable between threads. If the semaphore is not being shared between threads, the application should set pshared to 0 .
If successful, sem_init() returns 0 and initializes the semaphore in sem; otherwise it returns -1 and sets errno to indicate the error condition.
sem_destroy(), sem_post(), sem_wait()
Currently, semaphores are shared between threads. The value of the pshared argument is ignored.