1 /* Copyright (C) 2004-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 static pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
26 static pthread_mutex_t mut
= PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
;
27 static pthread_mutex_t mut2
= PTHREAD_MUTEX_INITIALIZER
;
32 if (pthread_mutex_lock (&mut
) != 0)
34 printf ("%s: 1st mutex_lock failed\n", __func__
);
37 if (pthread_mutex_lock (&mut
) != 0)
39 printf ("%s: 2nd mutex_lock failed\n", __func__
);
42 if (pthread_mutex_lock (&mut
) != 0)
44 printf ("%s: 3rd mutex_lock failed\n", __func__
);
48 if (pthread_mutex_unlock (&mut2
) != 0)
50 printf ("%s: mutex_unlock failed\n", __func__
);
54 if (pthread_cond_wait (&cond
, &mut
) != 0)
56 printf ("%s: cond_wait failed\n", __func__
);
69 if (pthread_mutex_lock (&mut2
) != 0)
71 puts ("1st mutex_lock failed");
75 puts ("parent: create child");
78 int err
= pthread_create (&th
, NULL
, tf
, NULL
);
81 printf ("parent: cannot create thread: %s\n", strerror (err
));
85 /* We have to synchronize with the child. */
86 if (pthread_mutex_lock (&mut2
) != 0)
88 puts ("2nd mutex_lock failed");
92 /* Give the child to reach to pthread_cond_wait. */
95 if (pthread_cond_signal (&cond
) != 0)
97 puts ("cond_signal failed");
101 err
= pthread_join (th
, NULL
);
104 printf ("parent: failed to join: %s\n", strerror (err
));
114 #define TEST_FUNCTION do_test ()
115 #include "../test-skeleton.c"