This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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;
  	}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]