initialize an unnamed semaphore
cc [options] -Kthread file
int sem_init(sem_t *sem, int pshared, unsigned int value);
sem_init initializes the unnamed semaphore sem.
Following a successful call to
sem_init, the semaphore may be used in
subsequent calls to sem_wait, sem_trywait,
sem_post, and sem_destroy.
This semaphore remains usable until the semaphore is destroyed.
sem is a pointer to an unnamed semaphore to be initialized.
If pshared has a non-zero value, then the semaphore
is shared between processes; in this case, any process that can
access the semaphore sem can use sem for
performing sem_wait, sem_trywait,
sem_post, and sem_destroy operations.
If the pshared argument is zero, then the
semaphore is shared between threads of the process;
any thread in this process can use sem for performing
sem_wait, sem_trywait, sem_post,
and sem_destroy operations.
value specifies the value of the initialized semaphore
value must be greater than or equal to zero.
sem_init returns zero for success.
Otherwise it returns -1 and sets errno
to indicate the error.
sem_init returns the following values
if the corresponding condition is detected:
value exceeds SEM_VALUE_MAX or is less than zero.
Attempting to initialize an already initialized semaphore
results in undefined behavior.
sem_init does not examine the sem argument
before initializing it.
If sem_init is called more than once for the same semaphore,
it will overwrite its state.
It is the user's responsibility to ensure that sem_init
is only called once for each semaphore.
The Single UNIX Specification, Version 2; The Open Group.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004