Subj : Re: Thoughts about threads in C++ To : comp.programming.threads From : Maciej Sobczak Date : Thu May 26 2005 11:10 am Hi, partow@gmail.com wrote: > Try this C++ library, I will give you directions > on how to create and use threads in a c++ context. In this thread (no pun intended) I claimed that the existence of threads should be acknowledged at the level of control statements and that the library approach will be always flawed in one way or another. > http://www.partow.net/programming/posixsynchwrapper/index.html This is a library. The Java-like approach (when you have to inherit from some Thread interface and pretend that your class Is_A thread) is indeed quite popular. I don't think, however, that this is the best you can get. Few comments considering your code: 1. You use explicit lock and unlock calls in your example code. This is not really C++. 2. The POSIXThread base class is copyable, but its copy constructor and assignment operator do nothing, not even copy the thread id (so the comparison operators are broken). You also use copyable derived thread classes in one of the example (you put them into the vector). I'm not sure whether this is really what you want to do (for example: can I join the copy of the original thread?). 3. The class POSIXScopeMutex makes no sense at all - how do you want to use it from multiple threads? 4. The POSIXCondition class contains *both* the condvar and the mutex as members. Is there any gain from doing this? Moreover, the wait() method takes no parameters. How can I wait for some *condition* (instead of just "signal") to take place? 5. Coming back to the POSIXThread base class, it contains the static member which is used as a thread start routine. This may not compile on some platforms, since class members (even if static) cannot be made extern "C". I don't claim that this list is complete. ;) -- Maciej Sobczak : http://www.msobczak.com/ Programming : http://www.msobczak.com/prog/ .