1SEM_POST(3P) POSIX Programmer's Manual SEM_POST(3P)
2
3
4
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
12 sem_post — unlock a semaphore
13
15 #include <semaphore.h>
16
17 int sem_post(sem_t *sem);
18
20 The sem_post() function shall unlock the semaphore referenced by sem by
21 performing a semaphore unlock operation on that semaphore.
22
23 If the semaphore value resulting from this operation is positive, then
24 no threads were blocked waiting for the semaphore to become unlocked;
25 the semaphore value is simply incremented.
26
27 If the value of the semaphore resulting from this operation is zero,
28 then one of the threads blocked waiting for the semaphore shall be
29 allowed to return successfully from its call to sem_wait(). If the
30 Process Scheduling option is supported, the thread to be unblocked
31 shall be chosen in a manner appropriate to the scheduling policies and
32 parameters in effect for the blocked threads. In the case of the sched‐
33 ulers SCHED_FIFO and SCHED_RR, the highest priority waiting thread
34 shall be unblocked, and if there is more than one highest priority
35 thread blocked waiting for the semaphore, then the highest priority
36 thread that has been waiting the longest shall be unblocked. If the
37 Process Scheduling option is not defined, the choice of a thread to
38 unblock is unspecified.
39
40 If the Process Sporadic Server option is supported, and the scheduling
41 policy is SCHED_SPORADIC, the semantics are as per SCHED_FIFO above.
42
43 The sem_post() function shall be async-signal-safe and may be invoked
44 from a signal-catching function.
45
47 If successful, the sem_post() function shall return zero; otherwise,
48 the function shall return -1 and set errno to indicate the error.
49
51 The sem_post() function may fail if:
52
53 EINVAL The sem argument does not refer to a valid semaphore.
54
55 The following sections are informative.
56
58 See sem_timedwait().
59
61 None.
62
64 None.
65
67 None.
68
70 semctl(), semget(), semop(), sem_timedwait(), sem_trywait()
71
72 The Base Definitions volume of POSIX.1‐2017, Section 4.12, Memory Syn‐
73 chronization, <semaphore.h>
74
76 Portions of this text are reprinted and reproduced in electronic form
77 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
78 table Operating System Interface (POSIX), The Open Group Base Specifi‐
79 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
80 Electrical and Electronics Engineers, Inc and The Open Group. In the
81 event of any discrepancy between this version and the original IEEE and
82 The Open Group Standard, the original IEEE and The Open Group Standard
83 is the referee document. The original Standard can be obtained online
84 at http://www.opengroup.org/unix/online.html .
85
86 Any typographical or formatting errors that appear in this page are
87 most likely to have been introduced during the conversion of the source
88 files to man page format. To report such errors, see https://www.ker‐
89 nel.org/doc/man-pages/reporting_bugs.html .
90
91
92
93IEEE/The Open Group 2017 SEM_POST(3P)