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
11

NAME

13       sem_init — initialize an unnamed semaphore
14

SYNOPSIS

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

DESCRIPTION

21       The sem_init() function shall initialize the unnamed semaphore referred
22       to  by  sem.   The  value  of the initialized semaphore shall be value.
23       Following a successful call to sem_init(), the semaphore may be used in
24       subsequent   calls   to   sem_wait(),  sem_timedwait(),  sem_trywait(),
25       sem_post(), and sem_destroy().   This  semaphore  shall  remain  usable
26       until the semaphore is destroyed.
27
28       If  the  pshared  argument  has a non-zero value, then the semaphore is
29       shared between processes; in this case, any process that can access the
30       semaphore  sem  can use sem for performing sem_wait(), sem_timedwait(),
31       sem_trywait(), sem_post(), and sem_destroy() operations.
32
33       Only sem itself may be used for performing synchronization. The  result
34       of  referring to copies of sem in calls to sem_wait(), sem_timedwait(),
35       sem_trywait(), sem_post(), and sem_destroy() is undefined.
36
37       If the pshared argument is zero, then the semaphore is  shared  between
38       threads of the process; any thread in this process can use sem for per‐
39       forming sem_wait(),  sem_timedwait(),  sem_trywait(),  sem_post(),  and
40       sem_destroy()  operations.  The  use  of the semaphore by threads other
41       than those created in the same process is undefined.
42
43       Attempting to initialize an already initialized  semaphore  results  in
44       undefined behavior.
45

RETURN VALUE

47       Upon  successful  completion,  the sem_init() function shall initialize
48       the semaphore in sem and return 0. Otherwise, it shall  return  −1  and
49       set errno to indicate the error.
50

ERRORS

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

EXAMPLES

66       None.
67

APPLICATION USAGE

69       None.
70

RATIONALE

72       None.
73

FUTURE DIRECTIONS

75       None.
76

SEE ALSO

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