1pthread_cond_init(3C) Standard C Library Functions pthread_cond_init(3C)
2
3
4
6 pthread_cond_init, pthread_cond_destroy - initialize or destroy condi‐
7 tion variables
8
10 cc -mt [ flag... ] file... -lpthread [ library... ]
11 #include <pthread.h>
12
13 int pthread_cond_init(pthread_cond_t *restrict cond,
14 const pthread_condattr_t *restrict attr);
15
16
17 int pthread_cond_destroy(pthread_cond_t *cond
18
19
20 pthread_cond_t cond= PTHREAD_COND_INITIALIZER;
21
22
24 The function pthread_cond_init() initializes the condition variable
25 referenced by cond with attributes referenced by attr. If attr is
26 NULL, the default condition variable attributes are used; the effect is
27 the same as passing the address of a default condition variable
28 attributes object. See pthread_condattr_init(3C). Upon successful ini‐
29 tialization, the state of the condition variable becomes initialized.
30
31
32 Attempting to initialize an already initialized condition variable
33 results in undefined behavior.
34
35
36 The function pthread_cond_destroy() destroys the given condition vari‐
37 able specified by cond; the object becomes, in effect, uninitialized.
38 An implementation may cause pthread_cond_destroy() to set the object
39 referenced by cond to an invalid value. A destroyed condition variable
40 object can be re-initialized using pthread_cond_init(); the results of
41 otherwise referencing the object after it has been destroyed are unde‐
42 fined.
43
44
45 It is safe to destroy an initialized condition variable upon which no
46 threads are currently blocked. Attempting to destroy a condition vari‐
47 able upon which other threads are currently blocked results in unde‐
48 fined behavior.
49
50
51 In cases where default condition variable attributes are appropriate,
52 the macro PTHREAD_COND_INITIALIZER can be used to initialize condition
53 variables that are statically allocated. The effect is equivalent to
54 dynamic initialization by a call to pthread_cond_init() with parameter
55 attr specified as NULL, except that no error checks are performed.
56
58 If successful, the pthread_cond_init() and pthread_cond_destroy() func‐
59 tions return 0. Otherwise, an error number is returned to indicate the
60 error. The EBUSY and EINVAL error checks, if implemented, act as if
61 they were performed immediately at the beginning of processing for the
62 function and caused an error return prior to modifying the state of the
63 condition variable specified by cond.
64
66 The pthread_cond_init() function will fail if:
67
68 EAGAIN The system lacked the necessary resources (other than memory)
69 to initialize another condition variable.
70
71
72 ENOMEM Insufficient memory exists to initialize the condition vari‐
73 able.
74
75
76
77 The pthread_cond_init() function may fail if:
78
79 EBUSY The implementation has detected an attempt to re-initialize
80 the object referenced by cond, a previously initialized, but
81 not yet destroyed, condition variable.
82
83
84 EINVAL The value specified by attr is invalid.
85
86
87
88 The pthread_cond_destroy() function may fail if:
89
90 EBUSY The implementation has detected an attempt to destroy the
91 object referenced by cond while it is referenced (for exam‐
92 ple, while being used in a pthread_cond_wait() or
93 pthread_cond_timedwait()) by another thread.
94
95
96 EINVAL The value specified by cond is invalid.
97
98
100 See attributes(5) for descriptions of the following attributes:
101
102
103
104
105 ┌─────────────────────────────┬─────────────────────────────┐
106 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
107 ├─────────────────────────────┼─────────────────────────────┤
108 │Interface Stability │Standard │
109 ├─────────────────────────────┼─────────────────────────────┤
110 │MT-Level │MT-Safe │
111 └─────────────────────────────┴─────────────────────────────┘
112
114 pthread_cond_signal(3C), pthread_cond_broadcast(3C),
115 pthread_cond_wait(3C), pthread_cond_timedwait(3C), pthread_con‐
116 dattr_init(3C), attributes(5), condition(5), standards(5)
117
118
119
120SunOS 5.11 23 Mar 2005 pthread_cond_init(3C)