man Pages(2): System Calls
只搜尋這本書
以 PDF 格式下載這本書

NAME

_lwp_sema_wait, _lwp_sema_trywait, _lwp_sema_init, _lwp_sema_post - semaphore operations

SYNOPSIS

#include <sys/lwp.h>
int _lwp_sema_wait(lwp_sema_t * sema);
int _lwp_sema_trywait(lwp_sema_t * sema);
int _lwp_sema_init(lwp_sema_t * sema,int count);
int _lwp_sema_post(lwp_sema_t * sema);

DESCRIPTION

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

RETURN VALUES

0 is returned when successful. A non-zero value indicates an error.

ERRORS

If any of the following conditions are detected, _lwp_sema_init( ), _lwp_sema_trywait( ), _lwp_sema_wait( ), and _lwp_sema_post( ) fail and return the corresponding value:
EINVAL
sema points to an invalid semaphore.
EFAULT
sema points to an illegal address.
EINTR
_lwp_sema_wait( ) was interrupted by a signal or fork(2).
EBUSY
_lwp_sema_trywait( ) was called on a semaphore with a zero count.

SEE ALSO

fork(2)