2003-02-08  Ulrich Drepper  <drepper@redhat.com>

	* tst-cond2.c: Rearrange code to not rely on behavior undefined
	according to POSIX.

	* tst-basic2.c (do_test): Lock mutex before creating the thread.
This commit is contained in:
Ulrich Drepper 2003-02-08 19:44:33 +00:00
parent 34c86f4254
commit 696e556ea9
3 changed files with 43 additions and 10 deletions

View File

@ -1,3 +1,10 @@
2003-02-08 Ulrich Drepper <drepper@redhat.com>
* tst-cond2.c: Rearrange code to not rely on behavior undefined
according to POSIX.
* tst-basic2.c (do_test): Lock mutex before creating the thread.
2003-02-07 Ulrich Drepper <drepper@redhat.com> 2003-02-07 Ulrich Drepper <drepper@redhat.com>
* sysdeps/x86_64/tls.h: Remove unnecessary macros, left over from x86. * sysdeps/x86_64/tls.h: Remove unnecessary macros, left over from x86.

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2002 Free Software Foundation, Inc. /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@ -58,6 +58,12 @@ do_test (void)
exit (1); exit (1);
} }
if (pthread_mutex_lock (&lock[i]) != 0)
{
puts ("mutex_lock failed");
exit (1);
}
if (pthread_create (&th[i], NULL, tf, (void *) i) != 0) if (pthread_create (&th[i], NULL, tf, (void *) i) != 0)
{ {
puts ("create failed"); puts ("create failed");

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2002 Free Software Foundation, Inc. /* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
@ -26,6 +26,8 @@
static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t syncm = PTHREAD_MUTEX_INITIALIZER;
static void * static void *
tf (void *a) tf (void *a)
@ -33,6 +35,18 @@ tf (void *a)
int i = (long int) a; int i = (long int) a;
int err; int err;
printf ("child %d: lock\n", i);
err = pthread_mutex_lock (&mut);
if (err != 0)
error (EXIT_FAILURE, err, "locking in child failed");
printf ("child %d: unlock sync\n", i);
err = pthread_mutex_unlock (&syncm);
if (err != 0)
error (EXIT_FAILURE, err, "child %d: unlock[1] failed", i);
printf ("child %d: wait\n", i); printf ("child %d: wait\n", i);
err = pthread_cond_wait (&cond, &mut); err = pthread_cond_wait (&cond, &mut);
@ -43,7 +57,7 @@ tf (void *a)
err = pthread_mutex_unlock (&mut); err = pthread_mutex_unlock (&mut);
if (err != 0) if (err != 0)
error (EXIT_FAILURE, err, "child %d: unlock failed", i); error (EXIT_FAILURE, err, "child %d: unlock[2] failed", i);
printf ("child %d: done\n", i); printf ("child %d: done\n", i);
@ -65,7 +79,7 @@ do_test (void)
puts ("first lock"); puts ("first lock");
err = pthread_mutex_lock (&mut); err = pthread_mutex_lock (&syncm);
if (err != 0) if (err != 0)
error (EXIT_FAILURE, err, "initial locking failed"); error (EXIT_FAILURE, err, "initial locking failed");
@ -80,16 +94,18 @@ do_test (void)
printf ("wait for child %d\n", i); printf ("wait for child %d\n", i);
/* Lock and thereby wait for the child to start up and get the /* Lock and thereby wait for the child to start up and get the
conditional variable. */ mutex for the conditional variable. */
pthread_mutex_lock (&mut); pthread_mutex_lock (&syncm);
/* Unlock right away. Yes, we can use barriers but then we
would test more functionality here. */
pthread_mutex_unlock (&syncm);
} }
puts ("final unlock"); puts ("get lock outselves");
/* Unlock in preparation of the broadcast. */ err = pthread_mutex_lock (&mut);
err = pthread_mutex_unlock (&mut);
if (err != 0) if (err != 0)
error (EXIT_FAILURE, err, "parent: unlock failed"); error (EXIT_FAILURE, err, "mut locking failed");
puts ("broadcast"); puts ("broadcast");
@ -98,6 +114,10 @@ do_test (void)
if (err != 0) if (err != 0)
error (EXIT_FAILURE, err, "parent: broadcast failed"); error (EXIT_FAILURE, err, "parent: broadcast failed");
err = pthread_mutex_unlock (&mut);
if (err != 0)
error (EXIT_FAILURE, err, "mut unlocking failed");
/* Join all threads. */ /* Join all threads. */
for (i = 0; i < N; ++i) for (i = 0; i < N; ++i)
{ {