From tessitore@athena.polito.it  Thu Aug 10 08:23:27 2000
Received: from menelao.polito.it (menelao.polito.it [130.192.3.30])
	by mescaline.gnu.org (8.9.1a/8.9.1) with SMTP id IAA25299
	for <bug-commoncpp@gnu.org>; Thu, 10 Aug 2000 08:23:26 -0400
Received: (qmail 22040 invoked from network); 10 Aug 2000 12:23:15 -0000
Received: from cselt6.polito.it (HELO cselt6) (130.192.14.21)
  by menelao.polito.it with SMTP; 10 Aug 2000 12:23:15 -0000
Message-Id: <4.1.20000810142340.009f0ab0@pop.polito.it>
X-Sender: tessitore@pop.polito.it
X-Mailer: QUALCOMM Windows Eudora Pro Version 4.1
Date: Thu, 10 Aug 2000 14:24:48 +0200
To: bug-commoncpp@gnu.org
From: Luca Tessitore <tessitore@athena.polito.it>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Subject: [Bug-commoncpp] (no subject)
Sender: bug-commoncpp-admin@gnu.org
Errors-To: bug-commoncpp-admin@gnu.org
X-BeenThere: bug-commoncpp@gnu.org
X-Mailman-Version: 2.0beta4
Precedence: bulk
List-Id: Bug reports for Common C++ <bug-commoncpp.gnu.org>

Good Morning,
	'm working with CommonC++ library under Solaris 8 and i found a bug in
Mutex. When a thread exit from mutual exclusion (Mutex::LeaveMutex()) other
thread can't enter in mutex too. Please see code belowe

 
 #include <thread.h>
 #include <config.h>
 #include <macros.h>
 #include <socket.h>
 
 class ThreadTest : public Thread
 {
   private:
    int  _threadID;
    Mutex * mutex;
 
    void Run()
    {
       cout << "Starting Thread " << _threadID << "\n";
 
       /*
       while (!mutex->TryEnterMutex()) {
          cout << "Mutex is busy ... sleep 1 second ("<< _threadID << ")\n";
          this->Sleep(1000);
       }
       */
       mutex->EnterMutex();
 
       for (int i=0; i<10; i++)
       {
 
          cout << "Thread ID="<< _threadID <<", loop number="<<(i+1)<< endl;
          this->Sleep(500);
 
       }
 
       mutex->LeaveMutex();
    };
 
    void Final()
    {
       cout << "Thread " << _threadID <<" exiting."<< endl;
       delete this;
    };
 
 public:
 
    ThreadTest(int threadID, Mutex * mutexPar): _threadID(threadID)
    {
       mutex = mutexPar; // initialise the mutex
    };
 
 };
 
 int main()
 {
    Mutex *m = new Mutex();
 
    ThreadTest *thread1 = new ThreadTest(1,m);
    ThreadTest *thread2 = new ThreadTest(2,m);
    ThreadTest *thread3 = new ThreadTest(3,m);
 
    cout << "Starting 3 threads named 1,2,3." << endl;
    thread1->Start();
    thread2->Start();
    thread3->Start();
  
    sleep(30);
 
    cout << "Main exiting." << endl;
    delete m;
    return 0;
 }
 
 When Thread1 finish is work Thread 2 stay blocked on mutex->EnterMutex()
 forever. I try the same code under Windows and Linux and all work better
 (when Thread1 leave mutual exclusion, Thread2 enter, work, leave and after
 Thread3 make is job).
 
 Sorry for my English :-)
 
 I hope it can be usefull for you!!!!
 
 Luca Tessitore
 


============================
Dott. Ing. Luca Tessitore

Address:	V. Circonvallazione 16
		10090 Montalenghe (TO)

Phone:	+39 011 9839295
Office:	+39 011 5647084
Mobile:	+39 0347 9778972
============================

