DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

sem_post(PTHREAD)


sem_post -- unlock a semaphore

Synopsis

   cc [options] -Kthread file
   

#include <semaphore.h>

int sem_post(sem_t *sem);

Description

sem_post increments the count of the semaphore pointed to by sem, and, if the new count value is less than or equal to zero, makes the next thread waiting at the semaphore runnable. If the semaphore value resulting from this operation is positive, then no threads were blocked waiting for the semaphore to become unlocked; the semaphore value is simply incremented.

sem is a pointer to the semaphore to increment and must previously have been initialized by sem_init.

The highest priority waiting thread will be unblocked, and if there is more than one highest priority thread blocked waiting for the semaphore, then the highest priority thread that has been waiting the longest will be unblocked.

sem_post is reentrant with respect to signals and may be invoked from a signal-catching function.

Return values

sem_post returns zero on success. Otherwise, it returns -1 and sets errno to indicate the error.

Diagnostics

sem_post returns -1 and sets errno to the following values if the corresponding conditions are detected:

EINVAL
invalid argument specified

Standards compliance

The Single UNIX Specification, Version 2; The Open Group.

References

Intro(PTHREAD), sem_destroy(PTHREAD), sem_init(PTHREAD), sem_trywait(PTHREAD), sem_wait(PTHREAD) semaphore(F)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005