Name

sem_post
- increment (unlock) a semaphore

Library

libpthread.lib

Synopsis

  #include <semaphore.h>
  int sem_post (sem_t *sem);

Return values

If successful, function shall return zero; otherwise, the function shall return -1 and set errno to indicate the error.

Detailed description

The sem_post function increments (unlocks) the semaphore pointed to by sem. If there are threads blocked on the semaphore when sem_post is called, then the highest priority thread that has been blocked the longest on the semaphore will be allowed to return from sem_wait.


Examples

sem_t psem;   
if (sem_init(&psem, 0, 1) < 0) {
        perror("sem_init");
        return -1;
   }
if( sem_post(psem) == -1 ) {
  perror( "sem_post failed");
  return -1;
 }


Errors

The sem_post function will fail if:
[EINVAL]
  The sem argument points to an invalid or uninitialized semaphore.

See also

sem_getvalue, sem_trywait in sem_wait, sem_wait


Feedback

For additional information or queries on this page send feedback

© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top