DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

sem_init(S)


sem_init -- initialize an unnamed semaphore

Syntax

cc . . . -lsuds
#include <semaphore.h>

int sem_init (sem_t *sem, int pshared, unsigned int value);

Description

The sem_init function is used to initialize the unnamed semaphore referred to by sem. The value of the initialized semaphore is value. Following a successful call to sem_init, the semaphore may be used in subsequent calls to sem_wait(S), sem_trywait(S), sem_post(S), and sem_destroy(S). This semaphore remains usable until it is destroyed.

If the pshared argument is non-zero, then the semaphore is shared between processes; in this case, any process which can access the semaphore sem can use sem for performing sem_wait, sem_trywait, sem_post and sem_destroy operations.

Only sem itself may be used for performing synchronization.

Return values

Upon successful completion, the function initializes the semaphore in sem. Otherwise, it returns -1 and sets errno to indicate the error.

Diagnostics

If any of the following conditions occur, the sem_init function returns -1 and sets errno to the corresponding value:

[EINVAL]
The value argument exceeds {SEM_VALUE_MAX}.

[ENOSPC]
A resource required to initialize the semaphore has been exhausted. The limit on semaphores, {SEM_NSEMS_MAX}, has been reached.

[EPERM]
The process lacks the appropriate privileges to initialize the semaphore.

See also

semaphore(FP), sem_destroy(S), sem_post(S), sem_trywait(S), sem_wait(S)

Standards conformance

Text reprinted and/or adapted from IEEE Std 1003.1b-1993, IEEE Standard for Information Technology, POSIX Part 1: System Application Program Interface (API) Amendment 1: Realtime Extensions [C Language], copyright © 1993 by the Institute of Electrical and Electronics Engineers, Inc. The IEEE takes no responsibility for and will assume no liability for damages resulting from the reader's misinterpretation of said information resulting from the placement and context in this publication. Information is reproduced with the permission of the IEEE.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003