SEM_POST(2) BSD System Calls Manual SEM_POST(2)NAME
sem_post -- unlock a semaphore
SYNOPSIS
#include <semaphore.h>
int
sem_post(sem_t *sem);
DESCRIPTION
The semaphore referenced by sem is unlocked, the value of the semaphore is incremented, and all threads which are waiting on the semaphore
are awakened.
sem_post() is reentrant with respect to signals and may be called from within a signal hanlder.
If successful, sem_post() will return 0. Otherwise, -1 is returned and errno is set.
ERRORS
sem_post() succeeds unless:
[EINVAL] sem is not a valid semaphore descriptor.
SEE ALSO sem_open(2), sem_trywait(2), sem_wait(2), semctl(2), semget(2), semop(2)HISTORY
sem_post() is specified in the POSIX Realtime Extension (1003.1b-1993/1003.1i-1995).
Darwin June 8, 2000 Darwin
Check Out this Related Man Page
sem_post(3) Library Functions Manual sem_post(3)NAME
sem_post - Unlocks a semaphore (P1003.1b)
LIBRARY
Realtime Library (librt.so, librt.a)
SYNOPSIS
#include <semaphore.h>
int sem_post (
sem_t *sem);
PARAMETERS
sem Pointer to the semaphore to be unlocked.
DESCRIPTION
The sem_post function unlocks the specified semaphore by performing the semaphore unlock operation on that semaphore. The appropriate func-
tion (sem_open for named semaphores or sem_init for unnamed semaphores) must be called for a semaphore before you can call the locking and
unlocking functions, sem_wait, sem_trywait, and sem_post.
If the semaphore value after a sem_post function is positive, no processes were blocked waiting for the semaphore to be unlocked; the sema-
phore value is incremented. If the semaphore value after a sem_post function is zero, one of the processes blocked waiting for the sema-
phore is allowed to return successfully from its call to sem_wait.
If more than one process is blocked while waiting for the semaphore, only one process is unblocked and the state of the semaphore remains
unchanged when the sem_post function returns. The process to be unblocked is selected according to the scheduling policies and priorities
of all blocked processes. If the scheduling policy is SCHED_FIFO or SCHED_RR, the highest-priority waiting process is unblocked. If more
than one process of that priority is blocked, then the process that has waited the longest is unblocked.
The sem_post function can be called from a signal-catching function.
RETURN VALUES
On successful completion, the sem_post function returns the value 0 (zero) and performs a semaphore unlock operation, unblocking a process.
Otherwise, the function returns the value -1 and sets errno to indicate the error. The state of the semaphore remains unchanged.
ERRORS
The sem_post function fails under the following condition:
[EINVAL] The sem does not refer to a valid semaphore.
RELATED INFORMATION
Functions: sem_trywait(3), sem_wait(3)
Guide to Realtime Programming delim off
sem_post(3)
Hi friends,
I have written this small program using the concept of semaphores. I am a bit confused, hope u can help me with it.
The idea is that
1. Two threads are created
2. First will be displaying 0(zero) on the screen
3. Second will be displaing 1(one) on the screen
4. This process... (2 Replies)
Hi friends,
I am using semaphores in my program, but when I compile the program, it gives the following error
$ gcc sem.c -o sem -lpthread
Undefined first referenced
symbol in file
sem_init ... (1 Reply)
hallo!
if there are many processes running and I initialize the semaphore like this:
my_sem = sem_open(SEM_NAME, O_CREAT | O_RDWR,
S_IRUSR | S_IWUSR, 10);
(the last argument is 10)
and then i use
sem_wait(my_sem);
sleep(5);
sem_post;
Will 10 processes be able to access the... (1 Reply)