1 /* Verify that exception table for pthread_cond_wait is correct.
2 Copyright (C) 2012 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
24 pthread_mutex_t mutex
;
27 #define CHECK_RETURN_VAL_OR_FAIL(ret,str) \
30 printf ("%s failed: %s\n", (str), strerror (ret)); \
40 puts ("clean: Unlocking mutex...");
41 pthread_mutex_unlock ((pthread_mutex_t
*) arg
);
42 puts ("clean: Mutex unlocked...");
49 pthread_mutexattr_t mutexAttr
;
50 ret
= pthread_mutexattr_init (&mutexAttr
);
51 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_mutexattr_init");
53 ret
= pthread_mutexattr_setprotocol (&mutexAttr
, PTHREAD_PRIO_INHERIT
);
54 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_mutexattr_setprotocol");
56 ret
= pthread_mutex_init (&mutex
, &mutexAttr
);
57 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_mutex_init");
59 ret
= pthread_cond_init (&cond
, 0);
60 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_cond_init");
62 puts ("th: Init done, entering wait...");
64 pthread_cleanup_push (clean
, (void *) &mutex
);
65 ret
= pthread_mutex_lock (&mutex
);
66 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_mutex_lock");
69 ret
= pthread_cond_wait (&cond
, &mutex
);
70 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_cond_wait");
72 pthread_cleanup_pop (1);
84 ret
= pthread_create (&thread
, 0, thr
, &thr_ret
);
85 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_create");
87 puts ("main: Thread created, waiting a bit...");
90 puts ("main: Cancelling thread...");
91 ret
= pthread_cancel (thread
);
92 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_cancel");
94 puts ("main: Joining th...");
95 ret
= pthread_join (thread
, NULL
);
96 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_join");
101 puts ("main: Joined thread, done!");
108 #include "../test-skeleton.c"