65 lines
2.2 KiB
Plaintext
65 lines
2.2 KiB
Plaintext
'\"macro stdmacro
|
|
.Op c p a
|
|
.TH sem_init 3C
|
|
.SH NAME
|
|
\f4sem_init\f1 \- initialize a posix unnamed semaphore
|
|
.SH SYNOPSIS
|
|
.nf
|
|
\f4#include <semaphore.h>\f1
|
|
.sp .6v
|
|
\f4int sem_init(sem_t *\f2sem\fP, int \f2pshared\fP, unsigned int \f2value\fP);\f1
|
|
.fi
|
|
.SH DESCRIPTION
|
|
.P
|
|
\f4sem_init\f1 initializes the unnamed semaphore located at address \f2sem\fP.
|
|
The address \f2sem\fP may reside anywhere in the calling processes address
|
|
space, but if the semaphore is intended to be shared across process boundaries,
|
|
\f2sem\fP must reside in shared memory.
|
|
.P
|
|
The \f2pshared\fP argument is used to specify whether the semaphore is intended
|
|
to be shared across process boundaries or only used locally by threads of
|
|
execution within a common process. If \f2pshared\fP is set to zero, then the
|
|
semaphore \f4is not\fP intended for sharing across process boundaries.
|
|
Conversely, a non-zero \f2pshared\fP value indicates any process having read
|
|
and write access to address \f2sem\fP, may perform semaphore operations
|
|
on \f2sem\fP. Unnamed semaphores have been optimized for local thread usage,
|
|
delivering increased performance within posix thread applications
|
|
[see \f4pthread_create\fP(3P)].
|
|
.P
|
|
The initial value of the semaphore is specified by \f2value\fP, which may
|
|
be any non-negative number less than {SEM_VALUE_MAX}
|
|
[see \f4sysconf\fP(3C)].
|
|
.P
|
|
POSIX semaphores are compatible across all MIPS ABIs: o32, n32 and 64.
|
|
.P
|
|
Once a semaphore is initialized, processes may execute the following
|
|
semaphore operations: \f4sem_post\fP, \f4sem_wait\fP, \f4sem_trywait\fP,
|
|
\f4sem_getvalue\fP, \f4sem_destroy\fP.
|
|
.P
|
|
\f4sem_init\f1 will fail if one or more of the following are true:
|
|
.TP 12
|
|
[EINVAL]
|
|
The \f2value\fP parameter was set to a number greater than {SEM_VALUE_MAX}.
|
|
.TP
|
|
[ENOSPC]
|
|
The resources required to initialize the semaphore have been depleted.
|
|
.TP
|
|
[EPERM]
|
|
The calling process lacks the permissions required to initialize the semaphore.
|
|
.SH SEE ALSO
|
|
sem_destroy(3C),
|
|
sem_getvalue(3C),
|
|
sem_post(3C),
|
|
sem_wait(3C),
|
|
sem_trywait(3C),
|
|
sem_open(3C),
|
|
sem_close(3C),
|
|
sem_unlink(3C),
|
|
shm_open(3C),
|
|
sysconf(3C),
|
|
mmap(3C)
|
|
.SH DIAGNOSTICS
|
|
Upon successful completion, a value of 0 is returned to the calling process.
|
|
Otherwise, a value of -1 is returned and \f4errno\fP is set to indicate
|
|
the error.
|