This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
make a linuxthread test safer
- From: Bruno Haible <bruno at clisp dot org>
- To: libc-alpha at sources dot redhat dot com
- Date: Fri, 20 Sep 2002 16:16:05 +0200 (CEST)
- Subject: make a linuxthread test safer
The linuxthreads/Examples/ex10.c test assumes that pthread_mutex_timedlock()
can only return 0 or ETIMEDOUT, but when you look at the implementation you
see that it can also return EINVAL. Therefore here is a patch to make the
test safer. (I haven't seen it fail this way - just to be sure.)
2002-09-17 Bruno Haible <bruno@clisp.org>
* Examples/ex10.c (thread): Fail if pthread_mutex_timedlock() returns
an unexpected error code.
diff -r -c3 glibc-20020910.bak/linuxthreads/Examples/ex10.c glibc-20020910/linuxthreads/Examples/ex10.c
*** glibc-20020910.bak/linuxthreads/Examples/ex10.c Tue Aug 27 13:38:43 2002
--- glibc-20020910/linuxthreads/Examples/ex10.c Tue Sep 17 02:22:03 2002
***************
*** 62,67 ****
--- 62,68 ----
for (;;)
{
+ int err;
clock_gettime (CLOCK_REALTIME, &ts);
***************
*** 72,78 ****
ts.tv_nsec -= 1000000000L;
}
! switch (pthread_mutex_timedlock (&mutex, &ts))
{
case 0:
flockfile (stdout);
--- 73,79 ----
ts.tv_nsec -= 1000000000L;
}
! switch ((err = pthread_mutex_timedlock (&mutex, &ts)))
{
case 0:
flockfile (stdout);
***************
*** 86,91 ****
--- 87,94 ----
(unsigned long) self);
funlockfile (stdout);
continue;
+ default:
+ error (EXIT_FAILURE, err, "pthread_mutex_timedlock failure");
}
break;
}