Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

sem_getvalue(3c) [opensolaris man page]

sem_getvalue(3C)					   Standard C Library Functions 					  sem_getvalue(3C)

NAME
sem_getvalue - get the value of a semaphore SYNOPSIS
#include <semaphore.h> int sem_getvalue(sem_t *restrict sem, int *restrict sval); DESCRIPTION
The sem_getvalue() function updates the location referenced by the sval argument to have the value of the semaphore referenced by sem with- out affecting the state of the semaphore. The updated value represents an actual semaphore value that occurred at some unspecified time during the call, but it need not be the actual value of the semaphore when it is returned to the calling process. If sem is locked, then the value returned by sem_getvalue() is either zero or a negative number whose absolute value represents the number of processes waiting for the semaphore at some unspecified time during the call. The value set in sval may be 0 or positive. If sval is 0, there may be other processes (or LWPs or threads) waiting for the semaphore; if sval is positive, no process is waiting. RETURN VALUES
Upon successful completion, sem_getvalue() returns 0. Otherwise, it returns -1 and sets errno to indicate the error. ERRORS
The sem_getvalue() function will fail if: EINVAL The sem argument does not refer to a valid semaphore. ENOSYS The sem_getvalue() function is not supported by the system. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ |Standard |See standards(5). | +-----------------------------+-----------------------------+ SEE ALSO
semctl(2), semget(2), semop(2), sem_post(3C), sem_wait(3C), attributes(5), standards(5) SunOS 5.11 5 Feb 2008 sem_getvalue(3C)

Check Out this Related Man Page

SEMAPHORES(3)						     Library Functions Manual						     SEMAPHORES(3)

NAME
sem_init, sem_wait, sem_trywait, sem_post, sem_getvalue, sem_destroy - operations on semaphores SYNOPSIS
#include <semaphore.h> int sem_init(sem_t *sem, int pshared, unsigned int value); int sem_wait(sem_t * sem); int sem_trywait(sem_t * sem); int sem_post(sem_t * sem); int sem_getvalue(sem_t * sem, int * sval); int sem_destroy(sem_t * sem); DESCRIPTION
This manual page documents POSIX 1003.1b semaphores, not to be confused with SystemV semaphores as described in ipc(5), semctl(2) and semop(2). Semaphores are counters for resources shared between threads. The basic operations on semaphores are: increment the counter atomically, and wait until the counter is non-null and decrement it atomically. sem_init initializes the semaphore object pointed to by sem. The count associated with the semaphore is set initially to value. The pshared argument indicates whether the semaphore is local to the current process ( pshared is zero) or is to be shared between several pro- cesses ( pshared is not zero). LinuxThreads currently does not support process-shared semaphores, thus sem_init always returns with error ENOSYS if pshared is not zero. sem_wait suspends the calling thread until the semaphore pointed to by sem has non-zero count. It then atomically decreases the semaphore count. sem_trywait is a non-blocking variant of sem_wait. If the semaphore pointed to by sem has non-zero count, the count is atomically decreased and sem_trywait immediately returns 0. If the semaphore count is zero, sem_trywait immediately returns with error EAGAIN. sem_post atomically increases the count of the semaphore pointed to by sem. This function never blocks and can safely be used in asynchro- nous signal handlers. sem_getvalue stores in the location pointed to by sval the current count of the semaphore sem. sem_destroy destroys a semaphore object, freeing the resources it might hold. No threads should be waiting on the semaphore at the time sem_destroy is called. In the LinuxThreads implementation, no resources are associated with semaphore objects, thus sem_destroy actually does nothing except checking that no thread is waiting on the semaphore. CANCELLATION
sem_wait is a cancellation point. ASYNC-SIGNAL SAFETY On processors supporting atomic compare-and-swap (Intel 486, Pentium and later, Alpha, PowerPC, MIPS II, Motorola 68k), the sem_post func- tion is async-signal safe and can therefore be called from signal handlers. This is the only thread synchronization function provided by POSIX threads that is async-signal safe. On the Intel 386 and the Sparc, the current LinuxThreads implementation of sem_post is not async-signal safe by lack of the required atomic operations. RETURN VALUE
The sem_wait and sem_getvalue functions always return 0. All other semaphore functions return 0 on success and -1 on error, in addition to writing an error code in errno. ERRORS
The sem_init function sets errno to the following codes on error: EINVAL value exceeds the maximal counter value SEM_VALUE_MAX ENOSYS pshared is not zero The sem_trywait function sets errno to the following error code on error: EAGAIN the semaphore count is currently 0 The sem_post function sets errno to the following error code on error: ERANGE after incrementation, the semaphore value would exceed SEM_VALUE_MAX (the semaphore count is left unchanged in this case) The sem_destroy function sets errno to the following error code on error: EBUSY some threads are currently blocked waiting on the semaphore. AUTHOR
Xavier Leroy <Xavier.Leroy@inria.fr> SEE ALSO
pthread_mutex_init(3), pthread_cond_init(3), pthread_cancel(3), ipc(5). LinuxThreads SEMAPHORES(3)
Man Page