1 /* Copyright (C) 2003, 2006 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, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 #include <sys/syscall.h>
31 struct timespec ts = { .tv_sec = 0, .tv_nsec = 200000000 }; \
32 while (syscall (__NR_nanosleep, &ts, &ts) < 0) \
38 static pthread_barrier_t b
;
46 int e
= pthread_barrier_wait (&b
);
47 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
49 printf ("%s: barrier_wait failed\n", __func__
);
56 pthread_join ((pthread_t
) arg
, NULL
);
66 int e
= pthread_barrier_wait (&b
);
67 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
69 printf ("%s: barrier_wait failed\n", __func__
);
75 pthread_join ((pthread_t
) arg
, NULL
);
85 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
87 puts ("barrier_init failed");
94 int err
= pthread_join (pthread_self (), NULL
);
97 puts ("1st circular join succeeded");
102 printf ("1st circular join %d, not EDEADLK\n", err
);
106 if (pthread_create (&th
, NULL
, tf1
, (void *) pthread_self ()) != 0)
108 puts ("1st create failed");
112 #ifndef WAIT_IN_CHILD
116 if (pthread_cancel (th
) != 0)
118 puts ("cannot cancel 1st thread");
123 int e
= pthread_barrier_wait (&b
);
124 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
126 printf ("%s: barrier_wait failed\n", __func__
);
132 err
= pthread_join (th
, &r
);
135 printf ("cannot join 1st thread: %d\n", err
);
138 if (r
!= PTHREAD_CANCELED
)
140 puts ("1st thread not canceled");
144 err
= pthread_join (pthread_self (), NULL
);
147 puts ("2nd circular join succeeded");
152 printf ("2nd circular join %d, not EDEADLK\n", err
);
156 if (pthread_create (&th
, NULL
, tf2
, (void *) pthread_self ()) != 0)
158 puts ("2nd create failed");
162 #ifndef WAIT_IN_CHILD
166 if (pthread_cancel (th
) != 0)
168 puts ("cannot cancel 2nd thread");
173 e
= pthread_barrier_wait (&b
);
174 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
176 printf ("%s: barrier_wait failed\n", __func__
);
181 if (pthread_join (th
, &r
) != 0)
183 puts ("cannot join 2nd thread");
186 if (r
!= PTHREAD_CANCELED
)
188 puts ("2nd thread not canceled");
192 err
= pthread_join (pthread_self (), NULL
);
195 puts ("3rd circular join succeeded");
200 printf ("3rd circular join %d, not EDEADLK\n", err
);
207 #define TEST_FUNCTION do_test ()
208 #include "../test-skeleton.c"