1SEM_INIT(3P)               POSIX Programmer's Manual              SEM_INIT(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       sem_init — initialize an unnamed semaphore
13

SYNOPSIS

15       #include <semaphore.h>
16
17       int sem_init(sem_t *sem, int pshared, unsigned value);
18

DESCRIPTION

20       The sem_init() function shall initialize the unnamed semaphore referred
21       to  by  sem.   The  value  of the initialized semaphore shall be value.
22       Following a successful call to sem_init(), the semaphore may be used in
23       subsequent   calls   to   sem_wait(),  sem_timedwait(),  sem_trywait(),
24       sem_post(), and sem_destroy().   This  semaphore  shall  remain  usable
25       until the semaphore is destroyed.
26
27       If  the  pshared  argument  has a non-zero value, then the semaphore is
28       shared between processes; in this case, any process that can access the
29       semaphore  sem  can use sem for performing sem_wait(), sem_timedwait(),
30       sem_trywait(), sem_post(), and sem_destroy() operations.
31
32       If the pshared argument is zero, then the semaphore is  shared  between
33       threads of the process; any thread in this process can use sem for per‐
34       forming sem_wait(),  sem_timedwait(),  sem_trywait(),  sem_post(),  and
35       sem_destroy() operations.
36
37       See  Section  2.9.9, Synchronization Object Copies and Alternative Map‐
38       pings for further requirements.
39
40       Attempting to initialize an already initialized  semaphore  results  in
41       undefined behavior.
42

RETURN VALUE

44       Upon  successful  completion,  the sem_init() function shall initialize
45       the semaphore in sem and return 0. Otherwise, it shall  return  -1  and
46       set errno to indicate the error.
47

ERRORS

49       The sem_init() function shall fail if:
50
51       EINVAL The value argument exceeds {SEM_VALUE_MAX}.
52
53       ENOSPC A  resource  required  to  initialize  the  semaphore  has  been
54              exhausted, or the limit on semaphores ({SEM_NSEMS_MAX}) has been
55              reached.
56
57       EPERM  The process lacks appropriate privileges to initialize the sema‐
58              phore.
59
60       The following sections are informative.
61

EXAMPLES

63       None.
64

APPLICATION USAGE

66       None.
67

RATIONALE

69       None.
70

FUTURE DIRECTIONS

72       None.
73

SEE ALSO

75       sem_destroy(), sem_post(), sem_timedwait(), sem_trywait()
76
77       The Base Definitions volume of POSIX.1‐2017, <semaphore.h>
78
80       Portions of this text are reprinted and reproduced in  electronic  form
81       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
82       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
83       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
84       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
85       event of any discrepancy between this version and the original IEEE and
86       The Open Group Standard, the original IEEE and The Open Group  Standard
87       is  the  referee document. The original Standard can be obtained online
88       at http://www.opengroup.org/unix/online.html .
89
90       Any typographical or formatting errors that appear  in  this  page  are
91       most likely to have been introduced during the conversion of the source
92       files to man page format. To report such errors,  see  https://www.ker
93       nel.org/doc/man-pages/reporting_bugs.html .
94
95
96
97IEEE/The Open Group                  2017                         SEM_INIT(3P)
Impressum