sema_trywait(3synch)


sema_trywait -- conditionally claim resources under the semaphore's control

Synopsis

   cc [options] -Kthread file
   

#include <synch.h>

int sema_trywait(sema_t *sema);

Description

sema_trywait makes a single attempt to acquire the semaphore pointed to by sema. If the semaphore is available, sema_trywait decrements the semaphore value and returns to the caller.

If sema_trywait cannot immediately acquire the semaphore, it returns EBUSY to the caller, it does not block the caller to wait for the semaphore or decrement the semaphore value.

Parameters


sema
pointer to the semaphore to acquire

sema parameter

sema must have been previously initialized, either by sema_init or statically (see sema_init(3synch)).

Usage

sema_trywait is used when the caller does not want to block if the semaphore is unavailable.

Return values

sema_trywait returns zero for success and an error number for failure.

Errors

If the following condition occurs, sema_trywait fails and returns the corresponding value:

EBUSY
the semaphore cannot be acquired immediately

If the following condition is detected, sema_trywait returns the corresponding value:


EINVAL
invalid argument specified

References

Intro(3synch), semaphore(3synch), sema_destroy(3synch), sema_init(3synch), sema_post(3synch), sema_wait(3synch)
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004