DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

_lwp_sema_wait(2)


_lwp_sema_wait -- acquire a semaphore

Synopsis

   #include <synch.h>
   

int _lwp_sema_wait(_lwp_sema_t *sema);

Parameters


sema
pointer to the semaphore to acquire

Description

_lwp_sema_wait attempts to acquire the semaphore pointed to by sema by decrementing the semaphore value. If the resulting value is greater than or equal to zero, it returns to the caller having successfully acquired the lock. If the semaphore count is zero or negative upon entry, _lwp_sema_wait suspends execution of the calling lightweight process (LWP) and places it on a queue associated with that semaphore where it remains until the lock becomes available to the caller, at which point _lwp_sema_wait returns with the lock held.

If an LWP waiting on a semaphore is interrupted by a signal, the signal handler will run, but _lwp_sema_wait is always restarted so the semaphore is acquired on return.

sema parameter

sema must previously have been initialized, either by _lwp_sema_init or statically (see _lwp_sema_init).

Return values

_lwp_sema_wait returns zero for success and an error number for failure, as described below.

Errors

If any of the following conditions is detected, _lwp_sema_wait fails and returns the corresponding value:

EFAULT
The sema parameter points to an illegal address. (This error may not be detected; a SIGSEGV signal may be posted to the faulting LWP if an illegal address is used.)
If any of the following conditions occurs, _lwp_sema_wait fails and returns the corresponding value:

EINTR
The operation was interrupted by a signal or a fork operation.

Usage

In general, this operation is used to block wait for an event, when a critical section is long.

References

_lwp_sema_init(2), _lwp_sema_post(2), _lwp_sema_trywait(2), sema_destroy(3synch), sema_init(3synch), sema_post(3synch), sema_trywait(3synch), sema_wait(3synch)

Notices

Lightweight processes (LWPs) are internal interfaces and are subject to change. Their use should be avoided.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004