1 /* Copyright (C) 2002-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
24 static pthread_mutex_t m
;
25 static pthread_barrier_t b
;
31 int e
= pthread_mutex_unlock (&m
);
34 puts ("child: 1st mutex_unlock succeeded");
39 puts ("child: 1st mutex_unlock error != EPERM");
43 e
= pthread_mutex_trylock (&m
);
46 puts ("child: 1st trylock suceeded");
51 puts ("child: 1st trylock didn't return EBUSY");
55 e
= pthread_barrier_wait (&b
);
56 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
58 puts ("child: 1st barrier_wait failed");
62 e
= pthread_barrier_wait (&b
);
63 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
65 puts ("child: 2nd barrier_wait failed");
69 e
= pthread_mutex_unlock (&m
);
72 puts ("child: 2nd mutex_unlock succeeded");
77 puts ("child: 2nd mutex_unlock error != EPERM");
81 if (pthread_mutex_trylock (&m
) != 0)
83 puts ("child: 2nd trylock failed");
87 if (pthread_mutex_unlock (&m
) != 0)
89 puts ("child: 3rd mutex_unlock failed");
100 pthread_mutexattr_t a
;
103 if (pthread_mutexattr_init (&a
) != 0)
105 puts ("mutexattr_init failed");
109 if (pthread_mutexattr_settype (&a
, PTHREAD_MUTEX_ERRORCHECK
) != 0)
111 puts ("mutexattr_settype failed");
116 if (pthread_mutexattr_setprotocol (&a
, PTHREAD_PRIO_INHERIT
) != 0)
118 puts ("pthread_mutexattr_setprotocol failed");
123 e
= pthread_mutex_init (&m
, &a
);
129 puts ("PI mutexes unsupported");
133 puts ("mutex_init failed");
137 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
139 puts ("barrier_init failed");
143 e
= pthread_mutex_unlock (&m
);
146 puts ("1st mutex_unlock succeeded");
151 puts ("1st mutex_unlock error != EPERM");
155 if (pthread_mutex_lock (&m
) != 0)
157 puts ("mutex_lock failed");
161 e
= pthread_mutex_lock (&m
);
164 puts ("2nd mutex_lock succeeded");
167 else if (e
!= EDEADLK
)
169 puts ("2nd mutex_lock error != EDEADLK");
174 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
176 puts ("create failed");
180 e
= pthread_barrier_wait (&b
);
181 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
183 puts ("1st barrier_wait failed");
187 if (pthread_mutex_unlock (&m
) != 0)
189 puts ("2nd mutex_unlock failed");
193 e
= pthread_mutex_unlock (&m
);
196 puts ("3rd mutex_unlock succeeded");
201 puts ("3rd mutex_unlock error != EPERM");
205 e
= pthread_barrier_wait (&b
);
206 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
208 puts ("2nd barrier_wait failed");
212 if (pthread_join (th
, NULL
) != 0)
214 puts ("join failed");
218 if (pthread_mutex_destroy (&m
) != 0)
220 puts ("mutex_destroy failed");
224 if (pthread_barrier_destroy (&b
) != 0)
226 puts ("barrier_destroy failed");
230 if (pthread_mutexattr_destroy (&a
) != 0)
232 puts ("mutexattr_destroy failed");
239 #define TEST_FUNCTION do_test ()
240 #include "../test-skeleton.c"