Multithreaded Programming Guide

Block on a Semaphore Count

Use sema_wait(3C) to block the calling thread until the count in the semaphore pointed to by sp becomes greater than zero. When the count becomes greater than zero, atomically decrement the count.

sema_wait Syntax

#include <thread.h>

int sema_wait(sema_t *sp);

sema_wait Return Values

sema_wait() returns 0 if successful. When any of the following conditions is detected, sema_wait() fails and returns the corresponding value.


EINVAL

Description:

sp refers to an invalid semaphore.


EINTR

Description:

The wait was interrupted by a signal.