SEM_INIT(3)                POSIX Programmer's Manual               SEM_INIT(3)



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

NNAAMMEE
       sem_init -- initialize an unnamed semaphore

SSYYNNOOPPSSIISS
       #include <semaphore.h>

       int sem_init(sem_t *_s_e_m, int _p_s_h_a_r_e_d, unsigned _v_a_l_u_e);

DDEESSCCRRIIPPTTIIOONN
       The _s_e_m___i_n_i_t() function shall initialize the unnamed semaphore referred
       to by _s_e_m.  The value of the initialized semaphore shall be _v_a_l_u_e.
       Following a successful call to _s_e_m___i_n_i_t(), the semaphore may be used in
       subsequent calls to _s_e_m___w_a_i_t(), _s_e_m___t_i_m_e_d_w_a_i_t(), _s_e_m___t_r_y_w_a_i_t(),
       _s_e_m___p_o_s_t(), and _s_e_m___d_e_s_t_r_o_y().  This semaphore shall remain usable
       until the semaphore is destroyed.

       If the _p_s_h_a_r_e_d argument has a non-zero value, then the semaphore is
       shared between processes; in this case, any process that can access the
       semaphore _s_e_m can use _s_e_m for performing _s_e_m___w_a_i_t(), _s_e_m___t_i_m_e_d_w_a_i_t(),
       _s_e_m___t_r_y_w_a_i_t(), _s_e_m___p_o_s_t(), and _s_e_m___d_e_s_t_r_o_y() operations.

       If the _p_s_h_a_r_e_d argument is zero, then the semaphore is shared between
       threads of the process; any thread in this process can use _s_e_m for
       performing _s_e_m___w_a_i_t(), _s_e_m___t_i_m_e_d_w_a_i_t(), _s_e_m___t_r_y_w_a_i_t(), _s_e_m___p_o_s_t(), and
       _s_e_m___d_e_s_t_r_o_y() operations.

       See _S_e_c_t_i_o_n _2_._9_._9, _S_y_n_c_h_r_o_n_i_z_a_t_i_o_n _O_b_j_e_c_t _C_o_p_i_e_s _a_n_d _A_l_t_e_r_n_a_t_i_v_e
       _M_a_p_p_i_n_g_s for further requirements.

       Attempting to initialize an already initialized semaphore results in
       undefined behavior.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, the _s_e_m___i_n_i_t() function shall initialize
       the semaphore in _s_e_m and return 0. Otherwise, it shall return -1 and
       set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       The _s_e_m___i_n_i_t() function shall fail if:

       EEIINNVVAALL The _v_a_l_u_e argument exceeds {SEM_VALUE_MAX}.

       EENNOOSSPPCC A resource required to initialize the semaphore has been
              exhausted, or the limit on semaphores ({SEM_NSEMS_MAX}) has been
              reached.

       EEPPEERRMM  The process lacks appropriate privileges to initialize the
              semaphore.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       None.

RRAATTIIOONNAALLEE
       None.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _s_e_m___d_e_s_t_r_o_y(), _s_e_m___p_o_s_t(), _s_e_m___t_i_m_e_d_w_a_i_t(), _s_e_m___t_r_y_w_a_i_t()

       The Base Definitions volume of POSIX.1-2017, <<sseemmaapphhoorree..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the
       Institute of Electrical and Electronics Engineers, Inc and The Open
       Group.  In the event of any discrepancy between this version and the
       original IEEE and The Open Group Standard, the original IEEE and The
       Open Group Standard is the referee document. The original Standard can
       be obtained online at http://www.opengroup.org/unix/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                          SEM_INIT(3)
