1 /* Copyright (C) 2002, 2003, 2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
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_mutex_t m
;
27 static pthread_barrier_t b
;
33 int e
= pthread_mutex_unlock (&m
);
36 puts ("child: 1st mutex_unlock succeeded");
41 puts ("child: 1st mutex_unlock error != EPERM");
45 e
= pthread_mutex_trylock (&m
);
48 puts ("child: 1st trylock suceeded");
53 puts ("child: 1st trylock didn't return EBUSY");
57 e
= pthread_barrier_wait (&b
);
58 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
60 puts ("child: 1st barrier_wait failed");
64 e
= pthread_barrier_wait (&b
);
65 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
67 puts ("child: 2nd barrier_wait failed");
71 e
= pthread_mutex_unlock (&m
);
74 puts ("child: 2nd mutex_unlock succeeded");
79 puts ("child: 2nd mutex_unlock error != EPERM");
83 if (pthread_mutex_trylock (&m
) != 0)
85 puts ("child: 2nd trylock failed");
89 if (pthread_mutex_unlock (&m
) != 0)
91 puts ("child: 3rd mutex_unlock failed");
102 pthread_mutexattr_t a
;
105 if (pthread_mutexattr_init (&a
) != 0)
107 puts ("mutexattr_init failed");
111 if (pthread_mutexattr_settype (&a
, PTHREAD_MUTEX_ERRORCHECK
) != 0)
113 puts ("mutexattr_settype failed");
118 if (pthread_mutexattr_setprotocol (&a
, PTHREAD_PRIO_INHERIT
) != 0)
120 puts ("pthread_mutexattr_setprotocol failed");
125 e
= pthread_mutex_init (&m
, &a
);
131 puts ("PI mutexes unsupported");
135 puts ("mutex_init failed");
139 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
141 puts ("barrier_init failed");
145 e
= pthread_mutex_unlock (&m
);
148 puts ("1st mutex_unlock succeeded");
153 puts ("1st mutex_unlock error != EPERM");
157 if (pthread_mutex_lock (&m
) != 0)
159 puts ("mutex_lock failed");
163 e
= pthread_mutex_lock (&m
);
166 puts ("2nd mutex_lock succeeded");
169 else if (e
!= EDEADLK
)
171 puts ("2nd mutex_lock error != EDEADLK");
176 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
178 puts ("create failed");
182 e
= pthread_barrier_wait (&b
);
183 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
185 puts ("1st barrier_wait failed");
189 if (pthread_mutex_unlock (&m
) != 0)
191 puts ("2nd mutex_unlock failed");
195 e
= pthread_mutex_unlock (&m
);
198 puts ("3rd mutex_unlock succeeded");
203 puts ("3rd mutex_unlock error != EPERM");
207 e
= pthread_barrier_wait (&b
);
208 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
210 puts ("2nd barrier_wait failed");
214 if (pthread_join (th
, NULL
) != 0)
216 puts ("join failed");
220 if (pthread_mutex_destroy (&m
) != 0)
222 puts ("mutex_destroy failed");
226 if (pthread_barrier_destroy (&b
) != 0)
228 puts ("barrier_destroy failed");
232 if (pthread_mutexattr_destroy (&a
) != 0)
234 puts ("mutexattr_destroy failed");
241 #define TEST_FUNCTION do_test ()
242 #include "../test-skeleton.c"