mirror of
git://sourceware.org/git/glibc.git
synced 2024-12-27 04:41:02 +08:00
5a82c74822
Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
153 lines
3.6 KiB
C
153 lines
3.6 KiB
C
/* Test of POSIX barriers.
|
|
Copyright (C) 2002-2019 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library; if not, see
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
#include <pthread.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#define NTHREADS 20
|
|
|
|
#define ROUNDS 20
|
|
|
|
static pthread_barrier_t barriers[NTHREADS];
|
|
|
|
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
|
|
static int counters[NTHREADS];
|
|
static int serial[NTHREADS];
|
|
|
|
static void *
|
|
worker (void *arg)
|
|
{
|
|
void *result = NULL;
|
|
int nr = (long int) arg;
|
|
int i;
|
|
|
|
for (i = 0; i < ROUNDS; ++i)
|
|
{
|
|
int j;
|
|
int retval;
|
|
|
|
if (nr == 0)
|
|
{
|
|
memset (counters, '\0', sizeof (counters));
|
|
memset (serial, '\0', sizeof (serial));
|
|
}
|
|
|
|
retval = pthread_barrier_wait (&barriers[NTHREADS - 1]);
|
|
if (retval != 0 && retval != PTHREAD_BARRIER_SERIAL_THREAD)
|
|
{
|
|
printf ("thread %d failed to wait for all the others\n", nr);
|
|
result = (void *) 1;
|
|
}
|
|
|
|
for (j = nr; j < NTHREADS; ++j)
|
|
{
|
|
/* Increment the counter for this round. */
|
|
pthread_mutex_lock (&lock);
|
|
++counters[j];
|
|
pthread_mutex_unlock (&lock);
|
|
|
|
/* Wait for the rest. */
|
|
retval = pthread_barrier_wait (&barriers[j]);
|
|
|
|
/* Test the result. */
|
|
if (nr == 0 && counters[j] != j + 1)
|
|
{
|
|
printf ("barrier in round %d released but count is %d\n",
|
|
j, counters[j]);
|
|
result = (void *) 1;
|
|
}
|
|
|
|
if (retval != 0)
|
|
{
|
|
if (retval != PTHREAD_BARRIER_SERIAL_THREAD)
|
|
{
|
|
printf ("thread %d in round %d has nonzero return value != PTHREAD_BARRIER_SERIAL_THREAD\n",
|
|
nr, j);
|
|
result = (void *) 1;
|
|
}
|
|
else
|
|
{
|
|
pthread_mutex_lock (&lock);
|
|
++serial[j];
|
|
pthread_mutex_unlock (&lock);
|
|
}
|
|
}
|
|
|
|
/* Wait for the rest again. */
|
|
retval = pthread_barrier_wait (&barriers[j]);
|
|
|
|
/* Now we can check whether exactly one thread was serializing. */
|
|
if (nr == 0 && serial[j] != 1)
|
|
{
|
|
printf ("not exactly one serial thread in round %d\n", j);
|
|
result = (void *) 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
#define TIMEOUT 60
|
|
static int
|
|
do_test (void)
|
|
{
|
|
pthread_t threads[NTHREADS];
|
|
int i;
|
|
void *res;
|
|
int result = 0;
|
|
|
|
/* Initialized the barrier variables. */
|
|
for (i = 0; i < NTHREADS; ++i)
|
|
if (pthread_barrier_init (&barriers[i], NULL, i + 1) != 0)
|
|
{
|
|
printf ("Failed to initialize barrier %d\n", i);
|
|
exit (1);
|
|
}
|
|
|
|
/* Start the threads. */
|
|
for (i = 0; i < NTHREADS; ++i)
|
|
if (pthread_create (&threads[i], NULL, worker, (void *) (long int) i) != 0)
|
|
{
|
|
printf ("Failed to start thread %d\n", i);
|
|
exit (1);
|
|
}
|
|
|
|
/* And wait for them. */
|
|
for (i = 0; i < NTHREADS; ++i)
|
|
if (pthread_join (threads[i], &res) != 0 || res != NULL)
|
|
{
|
|
printf ("thread %d returned a failure\n", i);
|
|
result = 1;
|
|
}
|
|
else
|
|
printf ("joined threads %d\n", i);
|
|
|
|
if (result == 0)
|
|
puts ("all OK");
|
|
|
|
return result;
|
|
}
|
|
|
|
#include "../test-skeleton.c"
|