next up previous contents
Next: Semaphore Signal Up: Semaphore Library Previous: Semaphore Initialization   Contents

Semaphore Wait

int sema_wait(struct sema * sem,unsigned int time)

The first argumenet sema is pointer the to the semaphore variable. time is the timeout associated with sema_wait. No timeout is enforced if time is -1.

The sema_wait function suspends the calling thread until the semaphore pointed to by sema has non-zero count, or timeout has expired. In case of timeout an error is returned. Otherwise the semaphore count is decremented atomically and 0 is returned.


Soumyadeb Mitra 2002-08-07