1 /* Copyright (C) 2003-2015 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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/>. */
30 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 200000000 };
31 while (nanosleep (&ts
, &ts
) < 0)
37 static pthread_barrier_t b
;
45 int e
= pthread_barrier_wait (&b
);
46 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
48 printf ("%s: barrier_wait failed\n", __func__
);
55 pthread_join ((pthread_t
) arg
, NULL
);
65 int e
= pthread_barrier_wait (&b
);
66 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
68 printf ("%s: barrier_wait failed\n", __func__
);
74 pthread_join ((pthread_t
) arg
, NULL
);
84 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
86 puts ("barrier_init failed");
93 int err
= pthread_join (pthread_self (), NULL
);
96 puts ("1st circular join succeeded");
101 printf ("1st circular join %d, not EDEADLK\n", err
);
105 if (pthread_create (&th
, NULL
, tf1
, (void *) pthread_self ()) != 0)
107 puts ("1st create failed");
111 #ifndef WAIT_IN_CHILD
115 if (pthread_cancel (th
) != 0)
117 puts ("cannot cancel 1st thread");
122 int e
= pthread_barrier_wait (&b
);
123 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
125 printf ("%s: barrier_wait failed\n", __func__
);
131 err
= pthread_join (th
, &r
);
134 printf ("cannot join 1st thread: %d\n", err
);
137 if (r
!= PTHREAD_CANCELED
)
139 puts ("1st thread not canceled");
143 err
= pthread_join (pthread_self (), NULL
);
146 puts ("2nd circular join succeeded");
151 printf ("2nd circular join %d, not EDEADLK\n", err
);
155 if (pthread_create (&th
, NULL
, tf2
, (void *) pthread_self ()) != 0)
157 puts ("2nd create failed");
161 #ifndef WAIT_IN_CHILD
165 if (pthread_cancel (th
) != 0)
167 puts ("cannot cancel 2nd thread");
172 e
= pthread_barrier_wait (&b
);
173 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
175 printf ("%s: barrier_wait failed\n", __func__
);
180 if (pthread_join (th
, &r
) != 0)
182 puts ("cannot join 2nd thread");
185 if (r
!= PTHREAD_CANCELED
)
187 puts ("2nd thread not canceled");
191 err
= pthread_join (pthread_self (), NULL
);
194 puts ("3rd circular join succeeded");
199 printf ("3rd circular join %d, not EDEADLK\n", err
);
206 #define TEST_FUNCTION do_test ()
207 #include "../test-skeleton.c"