]>
git.ipfire.org Git - thirdparty/glibc.git/blob - nptl/tst-join5.c
1 /* Copyright (C) 2003-2020 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 <https://www.gnu.org/licenses/>. */
26 #include <support/check.h>
27 #include <support/timespec.h>
28 #include <support/xthread.h>
29 #include <support/xtime.h>
34 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 200000000 };
35 while (nanosleep (&ts
, &ts
) < 0)
41 static pthread_barrier_t b
;
45 thread_join (pthread_t thread
, void **retval
)
47 #if defined USE_PTHREAD_TIMEDJOIN_NP
48 const struct timespec ts
= timespec_add (xclock_now (CLOCK_REALTIME
),
49 make_timespec (1000, 0));
50 return pthread_timedjoin_np (thread
, retval
, &ts
);
51 #elif defined USE_PTHREAD_CLOCKJOIN_NP_REALTIME
52 const struct timespec ts
= timespec_add (xclock_now (CLOCK_REALTIME
),
53 make_timespec (1000, 0));
54 return pthread_clockjoin_np (thread
, retval
, CLOCK_REALTIME
, &ts
);
55 #elif defined USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC
56 const struct timespec ts
= timespec_add (xclock_now (CLOCK_MONOTONIC
),
57 make_timespec (1000, 0));
58 return pthread_clockjoin_np (thread
, retval
, CLOCK_MONOTONIC
, &ts
);
60 return pthread_join (thread
, retval
);
69 xpthread_barrier_wait (&b
);
74 thread_join ((pthread_t
) arg
, NULL
);
84 xpthread_barrier_wait (&b
);
89 thread_join ((pthread_t
) arg
, NULL
);
99 xpthread_barrier_init (&b
, NULL
, 2);
104 int err
= thread_join (pthread_self (), NULL
);
107 puts ("1st circular join succeeded");
112 printf ("1st circular join %d, not EDEADLK\n", err
);
116 th
= xpthread_create (NULL
, tf1
, (void *) pthread_self ());
118 #ifndef WAIT_IN_CHILD
122 xpthread_cancel (th
);
125 xpthread_barrier_wait (&b
);
129 err
= thread_join (th
, &r
);
132 printf ("cannot join 1st thread: %d\n", err
);
135 if (r
!= PTHREAD_CANCELED
)
137 puts ("1st thread not canceled");
141 err
= thread_join (pthread_self (), NULL
);
144 puts ("2nd circular join succeeded");
149 printf ("2nd circular join %d, not EDEADLK\n", err
);
153 th
= xpthread_create (NULL
, tf2
, (void *) pthread_self ());
155 #ifndef WAIT_IN_CHILD
159 xpthread_cancel (th
);
162 xpthread_barrier_wait (&b
);
165 if (thread_join (th
, &r
) != 0)
167 puts ("cannot join 2nd thread");
170 if (r
!= PTHREAD_CANCELED
)
172 puts ("2nd thread not canceled");
176 err
= thread_join (pthread_self (), NULL
);
179 puts ("3rd circular join succeeded");
184 printf ("3rd circular join %d, not EDEADLK\n", err
);
191 #include <support/test-driver.c>