]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - tools/regression/pthread/unwind/cond_wait_cancel.cpp
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / tools / regression / pthread / unwind / cond_wait_cancel.cpp
1 /* $FreeBSD$ */
2 /* Test stack unwinding for pthread_cond_wait function */
3
4 #include <pthread.h>
5 #include <stdio.h>
6 #include <semaphore.h>
7 #include <unistd.h>
8
9 #include "Test.cpp"
10
11 pthread_mutex_t mtx;
12 pthread_cond_t cv;
13
14 void *
15 thr(void *arg)
16 {
17         Test t;
18
19         pthread_mutex_lock(&mtx);
20         pthread_cond_wait(&cv, &mtx);
21         pthread_mutex_unlock(&mtx);
22         printf("Bug, thread shouldn't be here.\n");
23         return (0);
24 }
25
26 int
27 main()
28 {
29         pthread_t td;
30
31         pthread_mutex_init(&mtx, NULL);
32         pthread_cond_init(&cv, NULL);
33         pthread_create(&td, NULL, thr, NULL);
34         sleep(1);
35         pthread_cancel(td);
36         pthread_join(td, NULL);
37         check_destruct();
38         return (0);
39 }