sem_init(3R) manual page
Table of Contents
sem_init - initialize an unnamed semaphore
cc [ flag ... ] file
... -lposix4 [ library ... ]
#include <semaphore.h>
int sem_init(sem_t *sem, int
pshared, unsigned int value );
typedef struct {
...
} sem_t; /*opaque POSIX.4 semaphore*/
MT-Safe
sem_init() is used to initialize the unnamed semaphore, referred
to by sem, to value. This semaphore may be used in subsequent calls to sem_wait(3R)
,
sem_trywait(3R)
, sem_post(3R)
, and sem_destroy(3R)
. This semaphore remains
usable until the semaphore is destroyed.
If pshared is non-zero, then the semaphore is sharable between processes.
If the semaphore is not being shared between processes, the application
should set pshared to 0.
If successful, sem_init() returns
0 and initializes the semaphore in sem; otherwise it returns -1 and sets
errno to indicate the error condition.
- EINVAL
- value exceeds SEM_VALUE_MAX.
- ENOSPC
- A resource required to initialize the semaphore has been exhausted.
The resources have reached the limit on semaphores, SEM_NSEMS_MAX.
- ENOSYS
- sem_init() is not supported by this implementation.
- EPERM
- The calling
process lacks the appropriate privileges to initialize the semaphore.
sem_destroy(3R)
, sem_post(3R)
, sem_wait(3R)
In Solaris 2.5, these
functions always return -1 and set errno
to ENOSYS,
because this release
does not support the Semaphores option. It is our intention to provide support
for these interfaces in future releases.
Table of Contents