1 /* Verify that exception table for pthread_cond_wait is correct.
2 Copyright (C) 2012-2015 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/>. */
25 pthread_mutex_t mutex
;
28 #define CHECK_RETURN_VAL_OR_FAIL(ret,str) \
31 printf ("%s failed: %s\n", (str), strerror (ret)); \
41 puts ("clean: Unlocking mutex...");
42 pthread_mutex_unlock ((pthread_mutex_t
*) arg
);
43 puts ("clean: Mutex unlocked...");
50 pthread_mutexattr_t mutexAttr
;
51 ret
= pthread_mutexattr_init (&mutexAttr
);
52 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_mutexattr_init");
54 ret
= pthread_mutexattr_setprotocol (&mutexAttr
, PTHREAD_PRIO_INHERIT
);
55 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_mutexattr_setprotocol");
57 ret
= pthread_mutex_init (&mutex
, &mutexAttr
);
58 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_mutex_init");
60 ret
= pthread_cond_init (&cond
, 0);
61 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_cond_init");
63 puts ("th: Init done, entering wait...");
65 pthread_cleanup_push (clean
, (void *) &mutex
);
66 ret
= pthread_mutex_lock (&mutex
);
67 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_mutex_lock");
70 ret
= pthread_cond_wait (&cond
, &mutex
);
71 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_cond_wait");
73 pthread_cleanup_pop (1);
76 return (void *) (uintptr_t) ret
;
85 ret
= pthread_create (&thread
, 0, thr
, &thr_ret
);
86 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_create");
88 puts ("main: Thread created, waiting a bit...");
91 puts ("main: Cancelling thread...");
92 ret
= pthread_cancel (thread
);
93 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_cancel");
95 puts ("main: Joining th...");
96 ret
= pthread_join (thread
, NULL
);
97 CHECK_RETURN_VAL_OR_FAIL (ret
, "pthread_join");
102 puts ("main: Joined thread, done!");
108 #define TEST_FUNCTION do_test ()
110 #include "../test-skeleton.c"