|
NAMEsema , sema_init ,
sema_destroy , sema_post ,
sema_wait , sema_timedwait ,
sema_trywait , sema_value
—
kernel counting semaphore
SYNOPSIS#include <sys/types.h>
#include <sys/lock.h>
#include <sys/sema.h>
void
void
void
void
int
int
int
DESCRIPTIONCounting semaphores provide a mechanism for synchronizing access to a pool of resources. Unlike mutexes, semaphores do not have the concept of an owner, so they can also be useful in situations where one thread needs to acquire a resource, and another thread needs to release it. Each semaphore has an integer value associated with it. Posting (incrementing) always succeeds, but waiting (decrementing) can only successfully complete if the resulting value of the semaphore is greater than or equal to zero.Semaphores should not be used where mutexes and condition variables will suffice. Semaphores are a more complex synchronization mechanism than mutexes and condition variables, and are not as efficient. Semaphores are created with RETURN VALUESThesema_value () function returns the current value of
the semaphore.
If decrementing the semaphore would result in its value being
negative, The ERRORSThesema_timedwait () function will fail if:
SEE ALSOcondvar(9), locking(9), mtx_pool(9), mutex(9), rwlock(9), sx(9)
Visit the GSP FreeBSD Man Page Interface. |