make a linuxthread test safer
Bruno Haible
bruno@clisp.org
Fri Sep 20 07:15:00 GMT 2002
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;
}
More information about the Libc-alpha
mailing list