-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathcond_attr.c
34 lines (31 loc) · 1010 Bytes
/
cond_attr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* cond_attr.c
*
* main() creates a condition variable using a non-default attributes object,
* cond_attr. If the implementation supports the pshared attribute, the
* condition variable is created "process private". (Note that, to create a
* "process shared" condition variable, the pthread_cond_t itself must be
* placed in shared memory that is accessible to all threads using the
* condition variable.)
*/
#include <pthread.h>
#include "errors.h"
pthread_cond_t cond;
int main (int argc, char *argv[])
{
pthread_condattr_t cond_attr;
int status;
status = pthread_condattr_init (&cond_attr);
if (status != 0)
err_abort (status, "Create attr");
#ifdef _POSIX_THREAD_PROCESS_SHARED
status = pthread_condattr_setpshared (
&cond_attr, PTHREAD_PROCESS_PRIVATE);
if (status != 0)
err_abort (status, "Set pshared");
#endif
status = pthread_cond_init (&cond, &cond_attr);
if (status != 0)
err_abort (status, "Init cond");
return 0;
}