sema_init(3scl)sema_init(3scl)NAMEsema_init - Initializes a semaphore.
LIBRARY
SCL Threads Library (libthread.so)
SYNOPSIS
#include <synch.h>
int sema_init(
sema_t *semp,
unsigned int count,
int type,
void *arg );
PARAMETERS
Pointer to the semaphore to be initialized. Initial value for the sem‐
aphore. Integer value indicating the type of semaphore required. Pos‐
sible values are: -for synchronization between threads within a single
process (process-wide scope) -for synchronization between threads in
different processes (system-wide scope). Unused. Typically NULL.
DESCRIPTION
This routine initializes the semaphore. A semaphore should be initial‐
ized by one thread only, before it is used by one or more threads.
SCL IMPLEMENTATION NOTESsema_init(3scl) is implemented by calling sem_init(3).
sem_init(3), and therefore sema_init(3scl) too, do not seem to return
an error if the semaphore to be initialized is already in use, though
this behaviour should not be relied upon.
This SCL implementation supports the use of semaphores for inter-
process synchronization (type is USYNC_PROCESS), but only when the pro‐
cesses are related (e.g. fork(2) is called to create multiple pro‐
cesses). This is because the semaphore object type sem_t on Tru64 UNIX
is not a stand-alone data-structure, but rather is an index into a
process-wide array of semaphores. (This is similar to how file descrip‐
tors are shared between forked processes).
RETURN VALUES
If an error condition occurs, this routine returns an integer value
indicating the type of error.
Additional error return information may be written to the SCL error
log. Refer to scl_error_log(4scl) for details.
Possible return values are as follows: Successful completion. The type
parameter is invalid. or:
sem_init(3) returned EINVAL, meaning that the count arguement exceeds
SEM_VALUE_MAX in <semaphore.h>. An internal implementation error
occurred. Refer to the SCL errorlog for additional information.
Note: EFAULT is not returned if semp is an illegal address. An illegal
address generates a SIGSEGV signal, which by default will abort the
process and generate a core dump.
ERRORS
None.
RELATED INFORMATION
Functions: fork(2), scl_intro(3scl), scl_thread_intro(3scl),
sem_init(3), sema_destroy(3scl), sema_post(3scl), sema_trywait(3scl),
sema_wait(3scl)
Files: scl_error_log(4scl)
Manuals: Solaris Compatibility Libraries User's Guide
sema_init(3scl)