2 * Invoke pthread_cond_destroy() on a condition variable that is being waited
8 #include <stdio.h> // printf()
11 static pthread_mutex_t s_mutex
;
12 static pthread_cond_t s_cond
;
15 static const char* err_to_str(int errnum
)
18 case 0: return "success";
19 case EBUSY
: return "EBUSY";
20 case EINVAL
: return "EINVAL";
25 static void* thread_func(void* thread_arg
)
27 pthread_mutex_lock(&s_mutex
);
29 pthread_cond_signal(&s_cond
);
31 pthread_cond_wait(&s_cond
, &s_mutex
);
32 pthread_mutex_unlock(&s_mutex
);
37 int main(int argc
, char** argv
)
42 pthread_mutex_init(&s_mutex
, 0);
43 pthread_cond_init(&s_cond
, 0);
45 pthread_create(&threadid
, 0, thread_func
, 0);
47 pthread_mutex_lock(&s_mutex
);
49 pthread_cond_wait(&s_cond
, &s_mutex
);
50 pthread_mutex_unlock(&s_mutex
);
52 ret
= pthread_cond_destroy(&s_cond
);
53 fprintf(stderr
, "First pthread_cond_destroy() call returned %s.\n",
56 pthread_mutex_lock(&s_mutex
);
58 pthread_cond_signal(&s_cond
);
59 pthread_mutex_unlock(&s_mutex
);
61 pthread_join(threadid
, 0);
63 ret
= pthread_cond_destroy(&s_cond
);
64 fprintf(stderr
, "Second pthread_cond_destroy() call returned %s.\n",
66 pthread_mutex_destroy(&s_mutex
);