Remove unused localedata/th_TH.in
[glibc.git] / sysdeps / pthread / tst-cond3.c
blob62519923bb87f3216b26682453d534548c18290a
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/>. */
18 #include <pthread.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
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;
38 #define N 10
41 static void *
42 tf (void *arg)
44 int i = (long int) arg;
45 int err;
47 /* Get the mutex. */
48 err = pthread_mutex_lock (&mut);
49 if (err != 0)
51 printf ("child %d mutex_lock failed: %s\n", i, strerror (err));
52 exit (1);
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. */
60 exit (1);
62 return NULL;
66 static int
67 do_test (void)
69 int err;
70 int i;
72 for (i = 0; i < N; ++i)
74 pthread_t th;
76 if (i != 0)
78 /* Release the mutex. */
79 err = pthread_mutex_unlock (&mut);
80 if (err != 0)
82 printf ("mutex_unlock %d failed: %s\n", i, strerror (err));
83 return 1;
87 err = pthread_create (&th, NULL, tf, (void *) (long int) i);
88 if (err != 0)
90 printf ("create %d failed: %s\n", i, strerror (err));
91 return 1;
94 /* Get the mutex. */
95 err = pthread_mutex_lock (&mut);
96 if (err != 0)
98 printf ("mutex_lock %d failed: %s\n", i, strerror (err));
99 return 1;
103 delayed_exit (1);
105 /* This call should never return. */
106 xpthread_cond_wait (&cond, &mut);
108 puts ("error: pthread_cond_wait in do_test returned");
109 return 1;