[libstdc++ PATCH/RFC] problem with pthread4 testcase

Jason R Thorpe thorpej@wasabisystems.com
Mon Oct 28 19:11:00 GMT 2002


The "pthread4" test seems to make the following assumptions:

	1. Test is being run on a multiprocessor, and thus the two
	   threads will run concurrently.

 -- or --

	2. If not run on a multiprocessor, that the threads will be
	   time-sliced against each other, thus creating the illusion
	   of concurrency.

#2 is a bogus assumption; POSIX does not specify the behavior of the
thread scheduler.

This bogus assumption causes this test to fall over with NetBSD's new
threads library on a uniprocessor.  Since the producer never does anything
which would cause it to block, the consumer never gets a chance to run.

The same problem exists in the consumer.

...and since no progress is ever made, dejagnu happily times the test out.

The following patch makes the test work for me, but I fear that it might
defeat the testcase.  I suppose one option is to yield only if __NetBSD__
is defined, or to simply not run the test for *-*-netbsd* ... however,
I see value in keeping this test for *-*-netbsd*, so I'd prefer not to
skip it.

If the libstdc++ maintainers agree that it does not defeat the test,
then I'll cook up a final patch to check in (i.e. address the FIXME
that's in the patch).

-- 
        -- Jason R. Thorpe <thorpej@wasabisystems.com>
-------------- next part --------------
Index: pthread4.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/thread/pthread4.cc,v
retrieving revision 1.4
diff -c -r1.4 pthread4.cc
*** pthread4.cc	28 Oct 2002 23:31:55 -0000	1.4
--- pthread4.cc	29 Oct 2002 03:09:04 -0000
***************
*** 31,36 ****
--- 31,40 ----
  // configured for the port, then it is picked up free from STL headers.
  
  #if __GTHREADS
+ // FIXME: Add an autoconf test for <sched.h> and wrap this in
+ // _GLIBCPP_HAVE_SCHED_H
+ #include <sched.h>
+ 
  using namespace std;
  
  static list<string> foo;
***************
*** 56,61 ****
--- 60,66 ----
  	  num++;
  	}
        pthread_mutex_unlock (&fooLock);
+       sched_yield ();
      }
  
    return 0;
***************
*** 74,79 ****
--- 79,85 ----
  	  num++;
  	}
        pthread_mutex_unlock (&fooLock);
+       sched_yield ();
      }
  
    return 0;


More information about the Gcc-patches mailing list