From 1142f82bf63944c01cfa90234ec9090edc57f032 Mon Sep 17 00:00:00 2001
From: ljrittle <ljrittle@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Thu, 15 May 2003 02:24:13 +0000
Subject: [PATCH] 	* testsuite/thread/pthread4.cc: Tweak test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@66817 138bc75d-0d04-0410-961f-82ee72b054a4
---
 libstdc++-v3/ChangeLog                    |  4 ++++
 libstdc++-v3/testsuite/thread/pthread4.cc | 16 +++++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 16972d8dfe9d..d5cb45daecb1 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,7 @@
+2003-05-14  Loren J. Rittle  <ljrittle@acm.org>
+
+	* testsuite/thread/pthread4.cc: Tweak test.
+
 2003-05-13  Benjamin Kosnik  <bkoz@redhat.com>
 
 	* testsuite/27_io/ios_base/cons/copy_neg.cc: Remove
diff --git a/libstdc++-v3/testsuite/thread/pthread4.cc b/libstdc++-v3/testsuite/thread/pthread4.cc
index 2636a5dd1c7e..d297fc28e67e 100644
--- a/libstdc++-v3/testsuite/thread/pthread4.cc
+++ b/libstdc++-v3/testsuite/thread/pthread4.cc
@@ -35,6 +35,8 @@ using namespace std;
 
 static list<string> foo;
 static pthread_mutex_t fooLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t fooCondOverflow = PTHREAD_COND_INITIALIZER;
+static pthread_cond_t fooCondUnderflow = PTHREAD_COND_INITIALIZER;
 static unsigned max_size = 10;
 #if defined(__CYGWIN__)
 static int iters = 10000;
@@ -50,11 +52,12 @@ produce (void*)
       string str ("test string");
 
       pthread_mutex_lock (&fooLock);
-      if (foo.size () < max_size)
-	{
-	  foo.push_back (str);
-	  num++;
-	}
+      while (foo.size () >= max_size)
+	pthread_cond_wait (&fooCondOverflow, &fooLock);
+      foo.push_back (str);
+      num++;
+      if (foo.size () >= (max_size / 2))
+	pthread_cond_signal (&fooCondUnderflow);
       pthread_mutex_unlock (&fooLock);
     }
 
@@ -67,12 +70,15 @@ consume (void*)
   for (int num = 0; num < iters; )
     {
       pthread_mutex_lock (&fooLock);
+      while (foo.size () == 0)
+	pthread_cond_wait (&fooCondUnderflow, &fooLock);
       while (foo.size () > 0)
 	{
 	  string str = foo.back ();
 	  foo.pop_back ();
 	  num++;
 	}
+      pthread_cond_signal (&fooCondOverflow);
       pthread_mutex_unlock (&fooLock);
     }
 
-- 
GitLab