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/>. */
36 static volatile bool done
;
42 puts ("child created");
44 if (pthread_setcancelstate (PTHREAD_CANCEL_ENABLE
, NULL
) != 0
45 || pthread_setcanceltype (PTHREAD_CANCEL_DEFERRED
, NULL
) != 0)
47 puts ("cannot set cancellation options");
53 if (pthread_mutex_lock (&t
->lock
) != 0)
55 puts ("child: lock failed");
61 if (pthread_cond_signal (&t
->cond
) != 0)
63 puts ("child: cond_signal failed");
67 if (pthread_cond_wait (&t
->cond
, &t
->lock
) != 0)
69 puts ("child: cond_wait failed");
73 if (pthread_mutex_unlock (&t
->lock
) != 0)
75 puts ("child: unlock failed");
89 for (i
= 0; i
< N
; ++i
)
91 printf ("round %d\n", i
);
93 t
[i
] = (T
*) malloc (sizeof (T
));
96 puts ("out of memory");
100 if (pthread_mutex_init (&t
[i
]->lock
, NULL
) != 0
101 || pthread_cond_init (&t
[i
]->cond
, NULL
) != 0)
103 puts ("an _init function failed");
107 if (pthread_mutex_lock (&t
[i
]->lock
) != 0)
109 puts ("initial mutex_lock failed");
115 if (pthread_create (&t
[i
]->h
, NULL
, tf
, t
[i
]) != 0)
117 puts ("pthread_create failed");
122 if (pthread_cond_wait (&t
[i
]->cond
, &t
[i
]->lock
) != 0)
124 puts ("cond_wait failed");
129 /* Release the lock since the cancel handler will get it. */
130 if (pthread_mutex_unlock (&t
[i
]->lock
) != 0)
132 puts ("mutex_unlock failed");
136 if (pthread_cancel (t
[i
]->h
) != 0)
138 puts ("cancel failed");
142 puts ("parent: joining now");
145 if (pthread_join (t
[i
]->h
, &result
) != 0)
147 puts ("join failed");
151 if (result
!= PTHREAD_CANCELED
)
153 puts ("result != PTHREAD_CANCELED");
158 for (i
= 0; i
< N
; ++i
)
165 #define TEST_FUNCTION do_test ()
166 #include "../test-skeleton.c"