Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ sem_ifwait(3) — OSF/1 X2.0-8 MIPS

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sem_close(3)

sem_open(3)

sem_post(3)

sem_wait(3)  —  Subroutines

Digital

NAME

sem_wait, sem_ifwait − Perform (or conditionally perform) a semaphore lock on a binary semaphore (P1003.4/D11). 

SYNOPSIS

#include <binsem.h>

int sem_wait (
binsemset_t binsemdes,
size_t binsemnum);

int sem_ifwait (
binsemset_t binsemdes,
size_t binsemnum);

PARAMETERS

binsemdes A binary semaphore set descriptor.  The binsemdes argument must be a valid binary semaphore set obtained by using the sem_open function. 

binsemnum The index of a binary semaphore in the set referenced by binsemdes.  The number must be in the range 0 to n−1, where n is the number of semaphores created with a call to the sem_mksem function. 

DESCRIPTION

The sem_wait function locks the specified semaphore by performing a semaphore lock operation on it. If the semaphore is currently locked, the sem_wait function blocks until it either locks the semaphore or is interrupted by a signal. 

The sem_ifwait is the same as the sem_wait function in that it locks the specified semaphore, but it is different in that sem_ifwait does not sleep. The sem_ifwait function locks a binary semaphore if and only if it can be locked without waiting for another process to unlock the binary semaphore. If the semaphore is locked, the sem_ifawit function returns without locking the semaphore. 

These functions help ensure that the resource associated with the binary semaphore cannot be accessed by other processes.  The binary semaphore remains locked until the process unlocks it with a call to the sem_post function. 

Use the sem_wait function instead of the sem_ifwait function if the process should wait for access to the semaphore. 

RETURN VALUES

If the sem_wait or sem_ifwait function returns successfully, a value of 0 is returned and the function executes the semaphore lock operation. 

On an unsuccessful call, a value of −1 is returned and errno is set to indicate that an error occurred. The state of the binary semaphore remains unchanged. 

ERRORS

The em_wait and sem_ifwait functions fail under the following conditions:

[EAGAIN] Process would be delayed in the sem_ifwait operation (sem_ifwait only). 

[EDEADLK] A deadlock condition was detected. 

[EINTR] A signal interrupted this function. 

[EINVAL] The binsemdes and binsemnum arguments together do not refer to a valid binary semaphore. 

[ENOSYS] The functions sem_wait and sem_ifwait are not supported by this implementation. 

RELATED INFORMATION

Functions: sem_close(3), sem_open(3), sem_post(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026