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/>. */
31 int r
= pthread_setcancelstate (PTHREAD_CANCEL_DISABLE
, &old
);
34 puts ("setcancelstate failed");
38 r
= pthread_barrier_wait (&b
);
39 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
41 puts ("barrier_wait failed");
45 for (int i
= 0; i
< 10; ++i
)
47 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
48 TEMP_FAILURE_RETRY (nanosleep (&ts
, &ts
));
52 pthread_setcancelstate (old
, NULL
);
54 struct timespec ts
= { .tv_sec
= 0, .tv_nsec
= 100000000 };
55 TEMP_FAILURE_RETRY (nanosleep (&ts
, &ts
));
64 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
66 puts ("barrier init failed");
71 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
73 puts ("thread creation failed");
77 int r
= pthread_barrier_wait (&b
);
78 if (r
!= 0 && r
!= PTHREAD_BARRIER_SERIAL_THREAD
)
80 puts ("barrier_wait failed");
84 if (pthread_cancel (th
) != 0)
86 puts ("cancel failed");
91 if (pthread_join (th
, &status
) != 0)
96 if (status
!= PTHREAD_CANCELED
)
98 puts ("thread not canceled");
102 if (pthread_barrier_destroy (&b
) != 0)
104 puts ("barrier_destroy failed");
110 puts ("thread cancelled when PTHREAD_CANCEL_DISABLED");
117 #define TEST_FUNCTION do_test ()
118 #include "../test-skeleton.c"