logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

sem_init.3p (3555B)


  1. '\" et
  2. .TH SEM_INIT "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. sem_init
  12. \(em initialize an unnamed semaphore
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <semaphore.h>
  17. .P
  18. int sem_init(sem_t *\fIsem\fP, int \fIpshared\fP, unsigned \fIvalue\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. \fIsem_init\fR()
  23. function shall initialize the unnamed semaphore referred to by
  24. .IR sem .
  25. The value of the initialized semaphore shall be
  26. .IR value .
  27. Following a successful call to
  28. \fIsem_init\fR(),
  29. the semaphore may be used in subsequent calls to
  30. \fIsem_wait\fR(),
  31. \fIsem_timedwait\fR(),
  32. \fIsem_trywait\fR(),
  33. \fIsem_post\fR(),
  34. and
  35. \fIsem_destroy\fR().
  36. This semaphore shall remain usable until the semaphore is destroyed.
  37. .P
  38. If the
  39. .IR pshared
  40. argument has a non-zero value, then the semaphore is shared between
  41. processes; in this case, any process that can access the semaphore
  42. .IR sem
  43. can use
  44. .IR sem
  45. for performing
  46. \fIsem_wait\fR(),
  47. \fIsem_timedwait\fR(),
  48. \fIsem_trywait\fR(),
  49. \fIsem_post\fR(),
  50. and
  51. \fIsem_destroy\fR()
  52. operations.
  53. .P
  54. If the
  55. .IR pshared
  56. argument is zero, then the semaphore is shared between threads of the
  57. process; any thread in this process can use
  58. .IR sem
  59. for performing
  60. \fIsem_wait\fR(),
  61. \fIsem_timedwait\fR(),
  62. \fIsem_trywait\fR(),
  63. \fIsem_post\fR(),
  64. and
  65. \fIsem_destroy\fR()
  66. operations.
  67. .P
  68. See
  69. .IR "Section 2.9.9" ", " "Synchronization Object Copies and Alternative Mappings"
  70. for further requirements.
  71. .P
  72. Attempting to initialize an already initialized semaphore results in
  73. undefined behavior.
  74. .SH "RETURN VALUE"
  75. Upon successful completion, the
  76. \fIsem_init\fR()
  77. function shall initialize the semaphore in
  78. .IR sem
  79. and return 0. Otherwise, it shall return \-1 and set
  80. .IR errno
  81. to indicate the error.
  82. .SH ERRORS
  83. The
  84. \fIsem_init\fR()
  85. function shall fail if:
  86. .TP
  87. .BR EINVAL
  88. The
  89. .IR value
  90. argument exceeds
  91. {SEM_VALUE_MAX}.
  92. .TP
  93. .BR ENOSPC
  94. A resource required to initialize the semaphore has been exhausted, or
  95. the limit on semaphores (\c
  96. {SEM_NSEMS_MAX})
  97. has been reached.
  98. .TP
  99. .BR EPERM
  100. The process lacks appropriate privileges to initialize the
  101. semaphore.
  102. .LP
  103. .IR "The following sections are informative."
  104. .SH EXAMPLES
  105. None.
  106. .SH "APPLICATION USAGE"
  107. None.
  108. .SH RATIONALE
  109. None.
  110. .SH "FUTURE DIRECTIONS"
  111. None.
  112. .SH "SEE ALSO"
  113. .IR "\fIsem_destroy\fR\^(\|)",
  114. .IR "\fIsem_post\fR\^(\|)",
  115. .IR "\fIsem_timedwait\fR\^(\|)",
  116. .IR "\fIsem_trywait\fR\^(\|)"
  117. .P
  118. The Base Definitions volume of POSIX.1\(hy2017,
  119. .IR "\fB<semaphore.h>\fP"
  120. .\"
  121. .SH COPYRIGHT
  122. Portions of this text are reprinted and reproduced in electronic form
  123. from IEEE Std 1003.1-2017, Standard for Information Technology
  124. -- Portable Operating System Interface (POSIX), The Open Group Base
  125. Specifications Issue 7, 2018 Edition,
  126. Copyright (C) 2018 by the Institute of
  127. Electrical and Electronics Engineers, Inc and The Open Group.
  128. In the event of any discrepancy between this version and the original IEEE and
  129. The Open Group Standard, the original IEEE and The Open Group Standard
  130. is the referee document. The original Standard can be obtained online at
  131. http://www.opengroup.org/unix/online.html .
  132. .PP
  133. Any typographical or formatting errors that appear
  134. in this page are most likely
  135. to have been introduced during the conversion of the source files to
  136. man page format. To report such errors, see
  137. https://www.kernel.org/doc/man-pages/reporting_bugs.html .