| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 2: System Calls Oracle Solaris 11 Information Library |
- semaphore operations
#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,intcount);
int_lwp_sema_post(lwp_sema_t *sema);
Conceptually, a semaphore is an non-negative integer count that is atomically incrementedand 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() waitsfor the count to become greater than 0 and then atomically decrements it.
LWP semaphores must be initialized before use. The_lwp_sema_init() function initializesthe count associated with the LWP semaphore pointed to bysema tocount.
The_lwp_sema_wait() function blocks the calling LWP until the semaphore count becomesgreater than 0 and then atomically decrements it.
The_lwp_sema_trywait() function atomically decrements the count if it is greater thanzero. Otherwise it returns an error.
The_lwp_sema_post() function atomically increments the semaphore count. If there are anyLWPs blocked on the semaphore, one is unblocked.
Upon successful completion,0 is returned. A non-zero value indicates an error.
The_lwp_sema_init(),_lwp_sema_trywait(),_lwp_sema_wait(), and_lwp_sema_post() functions will fail if:
Thesema argument points to an invalid semaphore.
Thesema argument points to an illegal address.
The_lwp_sema_wait() function will fail if:
The function execution was interrupted by a signal orfork(2).
The_lwp_sema_trywait() function will fail if:
The function was called on a semaphore with a zero count.
The_lwp_sema_post() function will fail if:
The value of thesema argument exceedsSEM_VALUE_MAX.
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |