1 /* Copyright (C) 2003-2024 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/>. */
25 #include <support/check.h>
26 #include <support/timespec.h>
27 #include <support/xthread.h>
28 #include <support/xtime.h>
33 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 200000000 };
34 while (nanosleep (&ts
, &ts
) < 0)
40 static pthread_barrier_t b
;
44 thread_join (pthread_t thread
, void **retval
)
46 #if defined USE_PTHREAD_TIMEDJOIN_NP
47 const struct timespec ts
= timespec_add (xclock_now (CLOCK_REALTIME
),
48 make_timespec (1000, 0));
49 return pthread_timedjoin_np (thread
, retval
, &ts
);
50 #elif defined USE_PTHREAD_CLOCKJOIN_NP_REALTIME
51 const struct timespec ts
= timespec_add (xclock_now (CLOCK_REALTIME
),
52 make_timespec (1000, 0));
53 return pthread_clockjoin_np (thread
, retval
, CLOCK_REALTIME
, &ts
);
54 #elif defined USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC
55 const struct timespec ts
= timespec_add (xclock_now (CLOCK_MONOTONIC
),
56 make_timespec (1000, 0));
57 return pthread_clockjoin_np (thread
, retval
, CLOCK_MONOTONIC
, &ts
);
59 return pthread_join (thread
, retval
);
68 xpthread_barrier_wait (&b
);
73 thread_join ((pthread_t
) arg
, NULL
);
83 xpthread_barrier_wait (&b
);
88 thread_join ((pthread_t
) arg
, NULL
);
98 xpthread_barrier_init (&b
, NULL
, 2);
103 int err
= thread_join (pthread_self (), NULL
);
106 puts ("1st circular join succeeded");
111 printf ("1st circular join %d, not EDEADLK\n", err
);
115 th
= xpthread_create (NULL
, tf1
, (void *) pthread_self ());
117 #ifndef WAIT_IN_CHILD
121 xpthread_cancel (th
);
124 xpthread_barrier_wait (&b
);
128 err
= thread_join (th
, &r
);
131 printf ("cannot join 1st thread: %d\n", err
);
134 if (r
!= PTHREAD_CANCELED
)
136 puts ("1st thread not canceled");
140 err
= thread_join (pthread_self (), NULL
);
143 puts ("2nd circular join succeeded");
148 printf ("2nd circular join %d, not EDEADLK\n", err
);
152 th
= xpthread_create (NULL
, tf2
, (void *) pthread_self ());
154 #ifndef WAIT_IN_CHILD
158 xpthread_cancel (th
);
161 xpthread_barrier_wait (&b
);
164 if (thread_join (th
, &r
) != 0)
166 puts ("cannot join 2nd thread");
169 if (r
!= PTHREAD_CANCELED
)
171 puts ("2nd thread not canceled");
175 err
= thread_join (pthread_self (), NULL
);
178 puts ("3rd circular join succeeded");
183 printf ("3rd circular join %d, not EDEADLK\n", err
);
190 #include <support/test-driver.c>