Conceptually, a semaphore is an non-negative integer count that is atomically incremented and decremented. Typically this represents the number of resources available. The _lwp_sema_init() function initializes the count, _lwp_sema_post() atomically increments the count, and _lwp_sema_wait() waits for the count to become greater than 0 and
then atomically decrements it.
LWP semaphores must be initialized before use. The _lwp_sema_init() function initializes the count associated with the LWP semaphore pointed to by sema to count.
The _lwp_sema_wait() function blocks the calling LWP until the semaphore count becomes greater than 0 and then atomically decrements it.
The _lwp_sema_trywait() function atomically decrements the count if it is greater than zero. Otherwise it returns an error.
The _lwp_sema_post() function atomically increments the semaphore count. If there are any LWPs blocked on the semaphore, one is unblocked.
|