1 /* Test for sem_post race: bug 14532.
2 Copyright (C) 2012-2015 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 #include <semaphore.h>
28 volatile int thread_fail;
33 for (int i = 0; i < NITER; i++)
35 if (sem_wait (&sem) != 0)
41 if (sem_post (&sem) != 0)
53 if (sem_init (&sem, 0, 0) != 0)
59 pthread_t th[NTHREADS];
60 for (int i = 0; i < NTHREADS; i++)
62 if (pthread_create (&th[i], NULL, tf, NULL) != 0)
64 puts ("pthread_create failed");
69 if (sem_post (&sem) != 0)
75 for (int i = 0; i < NTHREADS; i++)
76 if (pthread_join (th[i], NULL) != 0)
78 puts ("pthread_join failed");
82 if (c != NTHREADS * NITER)
84 printf ("c = %d, should be %d\n", c, NTHREADS * NITER);
91 #define TEST_FUNCTION do_test ()
92 #include "../test-skeleton.c"