1 /* Copyright (C) 2003-2013 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/>. */
25 #include <sys/syscall.h>
27 #if !defined(__NR_nanosleep) && defined(SYS_nanosleep)
28 # define __NR_nanosleep SYS_nanosleep
33 struct timespec ts = { .tv_sec = 0, .tv_nsec = 200000000 }; \
34 while (syscall (__NR_nanosleep, &ts, &ts) < 0) \
40 static pthread_barrier_t b
;
48 int e
= pthread_barrier_wait (&b
);
49 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
51 printf ("%s: barrier_wait failed\n", __func__
);
58 pthread_join ((pthread_t
) arg
, NULL
);
68 int e
= pthread_barrier_wait (&b
);
69 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
71 printf ("%s: barrier_wait failed\n", __func__
);
77 pthread_join ((pthread_t
) arg
, NULL
);
87 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
89 puts ("barrier_init failed");
96 int err
= pthread_join (pthread_self (), NULL
);
99 puts ("1st circular join succeeded");
104 printf ("1st circular join %d, not EDEADLK\n", err
);
108 if (pthread_create (&th
, NULL
, tf1
, (void *) pthread_self ()) != 0)
110 puts ("1st create failed");
114 #ifndef WAIT_IN_CHILD
118 if (pthread_cancel (th
) != 0)
120 puts ("cannot cancel 1st thread");
125 int e
= pthread_barrier_wait (&b
);
126 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
128 printf ("%s: barrier_wait failed\n", __func__
);
134 err
= pthread_join (th
, &r
);
137 printf ("cannot join 1st thread: %d\n", err
);
140 if (r
!= PTHREAD_CANCELED
)
142 puts ("1st thread not canceled");
146 err
= pthread_join (pthread_self (), NULL
);
149 puts ("2nd circular join succeeded");
154 printf ("2nd circular join %d, not EDEADLK\n", err
);
158 if (pthread_create (&th
, NULL
, tf2
, (void *) pthread_self ()) != 0)
160 puts ("2nd create failed");
164 #ifndef WAIT_IN_CHILD
168 if (pthread_cancel (th
) != 0)
170 puts ("cannot cancel 2nd thread");
175 e
= pthread_barrier_wait (&b
);
176 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
178 printf ("%s: barrier_wait failed\n", __func__
);
183 if (pthread_join (th
, &r
) != 0)
185 puts ("cannot join 2nd thread");
188 if (r
!= PTHREAD_CANCELED
)
190 puts ("2nd thread not canceled");
194 err
= pthread_join (pthread_self (), NULL
);
197 puts ("3rd circular join succeeded");
202 printf ("3rd circular join %d, not EDEADLK\n", err
);
209 #define TEST_FUNCTION do_test ()
210 #include "../test-skeleton.c"