1 /* Copyright (C) 2002-2023 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/>. */
24 static int do_test (void);
26 #define TEST_FUNCTION do_test ()
27 #include "../test-skeleton.c"
29 /* Note that this test requires more than the standard. It is
30 required that there are no spurious wakeups if only more readers
31 are added. This is a reasonable demand. */
34 static pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
35 static pthread_mutex_t mut
= PTHREAD_MUTEX_INITIALIZER
;
44 int i
= (long int) arg
;
48 err
= pthread_mutex_lock (&mut
);
51 printf ("child %d mutex_lock failed: %s\n", i
, strerror (err
));
55 /* This call should never return. */
56 xpthread_cond_wait (&cond
, &mut
);
57 puts ("error: pthread_cond_wait in tf returned");
59 /* We should never get here. */
72 for (i
= 0; i
< N
; ++i
)
78 /* Release the mutex. */
79 err
= pthread_mutex_unlock (&mut
);
82 printf ("mutex_unlock %d failed: %s\n", i
, strerror (err
));
87 err
= pthread_create (&th
, NULL
, tf
, (void *) (long int) i
);
90 printf ("create %d failed: %s\n", i
, strerror (err
));
95 err
= pthread_mutex_lock (&mut
);
98 printf ("mutex_lock %d failed: %s\n", i
, strerror (err
));
105 /* This call should never return. */
106 xpthread_cond_wait (&cond
, &mut
);
108 puts ("error: pthread_cond_wait in do_test returned");