1 /* Copyright (C) 2005 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2005.
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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 static pthread_barrier_t b
;
27 static pthread_cond_t c
= PTHREAD_COND_INITIALIZER
;
28 static pthread_mutex_t m
;
29 static bool first
= true;
35 long int n
= (long int) arg
;
37 if (pthread_mutex_lock (&m
) != 0)
39 printf ("thread %ld: mutex_lock failed\n", n
+ 1);
43 int e
= pthread_barrier_wait (&b
);
44 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
46 printf ("thread %ld: barrier_wait failed\n", n
+ 1);
50 e
= pthread_cond_wait (&c
, &m
);
55 printf ("thread %ld: cond_wait failed\n", n
+ 1);
64 printf ("thread %ld: cond_wait did not return EOWNERDEAD\n", n
+ 1);
69 if (pthread_cancel (pthread_self ()) != 0)
71 printf ("thread %ld: cancel failed\n", n
+ 1);
75 pthread_testcancel ();
77 printf ("thread %ld: testcancel returned\n", n
+ 1);
85 pthread_mutexattr_t a
;
86 if (pthread_mutexattr_init (&a
) != 0)
88 puts ("mutexattr_init failed");
92 if (pthread_mutexattr_setrobust_np (&a
, PTHREAD_MUTEX_ROBUST_NP
) != 0)
94 puts ("mutexattr_setrobust failed");
98 if (pthread_mutex_init (&m
, &a
) != 0)
100 puts ("mutex_init failed");
104 if (pthread_mutexattr_destroy (&a
) != 0)
106 puts ("mutexattr_destroy failed");
110 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
112 puts ("barrier_init failed");
118 for (long int n
= 0; n
< N
; ++n
)
120 if (pthread_create (&th
[n
], NULL
, tf
, (void *) n
) != 0)
122 printf ("pthread_create loop %ld failed\n", n
+ 1);
126 int e
= pthread_barrier_wait (&b
);
127 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
129 printf ("parent: barrier_wait failed in round %ld\n", n
+ 1);
134 if (pthread_mutex_lock (&m
) != 0)
136 puts ("parent: mutex_lock failed");
140 if (pthread_mutex_unlock (&m
) != 0)
142 puts ("parent: mutex_unlock failed");
146 if (pthread_cond_broadcast (&c
) != 0)
148 puts ("cond_broadcast failed");
152 for (int n
= 0; n
< N
; ++n
)
155 if (pthread_join (th
[n
], &res
) != 0)
157 printf ("join round %d failed\n", n
+ 1);
160 if (res
!= PTHREAD_CANCELED
)
162 printf ("thread %d not canceled\n", n
+ 1);
167 int e
= pthread_mutex_lock (&m
);
170 puts ("parent: 2nd mutex_lock succeeded");
175 puts ("parent: mutex_lock did not return EOWNERDEAD");
179 if (pthread_mutex_unlock (&m
) != 0)
181 puts ("parent: 2nd mutex_unlock failed");
185 if (pthread_mutex_destroy (&m
) != 0)
187 puts ("mutex_destroy failed");
194 #define TEST_FUNCTION do_test ()
195 #include "../test-skeleton.c"