bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Thread termination & Mutex bug?


From: NTR
Subject: Thread termination & Mutex bug?
Date: Tue, 1 Apr 2003 13:35:54 +0200

Hi,

I have been working with CommonC++ 1.9.1 on Win2000 using the Thread, Mutex,
Semaphore classes in a multi-threaded and I'm having problems with
terminating threads from "main(...)" as this cannot call "Terminate()" as it
is protected. What is the reason for this? Couldn't it be public instead?
Could I just derive my own thread class and make a public "MyTerminate"
method which calls "this->Terminate()"?

Anyway, I assume there is a good reason for this so ... how can I terminate
a thread from the main method? I have noticed the Thread(bool), which is
supposed to construct a context for the main thread. However, I have no idea
how to use this ... if anybody has an example it would be highly
appreciated.

In addition, I'm experiencing problems with Mutex and Semaphore not being
thread safe in a producer/consumer scenario. Is this a known bug in 1.9.1?

My scenario is something like:
main()
{
   ProducerConsumerBuffer buf;
   ProducerThread prod(buf);//Puts data in buf ... overwrites data in buf
   ConsumerThread cons(buf);//Waits on semaphore for data in buf
   prod.Start();
   cons.Start();

   ccxx_sleep(100000);//In my case I process user input until ESC has been
pressed

   //Due to various reasons I cannot simply let threads
   //delete themselves when the main thread stops but have
   //to stop the threads first
   prod.Terminate();//WRONG
   cons.Terminate();//WRONG
}

Regards,
Niels

PS: Is the new commoncpp2 1.0.x endiansafe for TCP transmission from a Win32
to an Irix 6.5 SGI computer? The reason I'm using 1.9.1 is that some other
people have modified this version to be endiansafe for TCP transmission. I
think they submitted a bug report...
PPS: I have previously downloaded commoncpp2 1.0.8, but haven't had any luck
compiling it (without XML) on Win2000 is this still a problem?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]