1_lwp_sema_wait(2)                System Calls                _lwp_sema_wait(2)
2
3
4

NAME

6       _lwp_sema_wait,  _lwp_sema_trywait,  _lwp_sema_init,  _lwp_sema_post  -
7       semaphore operations
8

SYNOPSIS

10       #include <sys/lwp.h>
11
12       int _lwp_sema_wait(lwp_sema_t *sema);
13
14
15       int _lwp_sema_trywait(lwp_sema_t *sema);
16
17
18       int _lwp_sema_init(lwp_sema_t *sema, int count);
19
20
21       int _lwp_sema_post(lwp_sema_t *sema);
22
23

DESCRIPTION

25       Conceptually, a semaphore is an  non-negative  integer  count  that  is
26       atomically  incremented  and decremented. Typically this represents the
27       number of resources available. The _lwp_sema_init()  function  initial‐
28       izes  the  count, _lwp_sema_post() atomically increments the count, and
29       _lwp_sema_wait() waits for the count to become greater than 0 and  then
30       atomically decrements it.
31
32
33       LWP  semaphores  must  be initialized before use.  The _lwp_sema_init()
34       function initializes  the  count  associated  with  the  LWP  semaphore
35       pointed to by sema to count.
36
37
38       The  _lwp_sema_wait()  function  blocks the calling LWP until the sema‐
39       phore count becomes greater than 0 and then atomically decrements it.
40
41
42       The _lwp_sema_trywait() function atomically decrements the count if  it
43       is greater than zero. Otherwise it returns an error.
44
45
46       The  _lwp_sema_post()  function  atomically  increments  the  semaphore
47       count. If  there  are  any  LWPs  blocked  on  the  semaphore,  one  is
48       unblocked.
49

RETURN VALUES

51       Upon  successful  completion, 0 is returned. A non-zero value indicates
52       an error.
53

ERRORS

55       The  _lwp_sema_init(),   _lwp_sema_trywait(),   _lwp_sema_wait(),   and
56       _lwp_sema_post() functions will fail if:
57
58       EINVAL    The sema argument points to an invalid semaphore.
59
60
61       EFAULT    The sema argument points to an illegal address.
62
63
64
65       The  _lwp_sema_wait() function will fail if:
66
67       EINTR    The function execution was interrupted by a signal or fork(2).
68
69
70
71       The  _lwp_sema_trywait() function will fail if:
72
73       EBUSY    The function was called on a semaphore with a zero count.
74
75
76
77       The  _lwp_sema_post() function will fail if:
78
79       EOVERFLOW    The value of the sema argument exceeds SEM_VALUE_MAX.
80
81

SEE ALSO

83       fork(2)
84
85
86
87SunOS 5.11                        8 May 1998                 _lwp_sema_wait(2)
Impressum