G
gwowen
I wrote a simple wrapper class around pthreads to implement a
producer/consumer thread pool. A simplified form resembled this:
#include <pthread.h>
class C
{
pthread_cond_t m_cond;
}
// with constructor
C::C ()
: m_cond(PTHREAD_COND_INTIALIZER)
{}
On win32 g++/mingw, this compiled beautifully, but on Linux, it
didn't.
This is because the typedefs differ.
On Linux, pthread_cond_t is a struct, and the macro PTHREAD_COND_T is
(something like) {0,0,NULL,0}, which can't be used in an
initialization list.
On Win32 pthread_cond_t is a pointer to an incomplete type.
Local coding standards say I should initialize the compound in the
initialization list.
Is this possible without doing, say the following:
namespace {
static const pthread_cond_t
pthread_cond_intializer = PTHREAD_COND_INTIALIZER;
}
C::C ()
: m_cond(pthread_cond_intializer)
{}
Will it be possible in C++0x?
(Yes, I know boost::thread...
It was an exercise, more than anything else.)
producer/consumer thread pool. A simplified form resembled this:
#include <pthread.h>
class C
{
pthread_cond_t m_cond;
}
// with constructor
C::C ()
: m_cond(PTHREAD_COND_INTIALIZER)
{}
On win32 g++/mingw, this compiled beautifully, but on Linux, it
didn't.
This is because the typedefs differ.
On Linux, pthread_cond_t is a struct, and the macro PTHREAD_COND_T is
(something like) {0,0,NULL,0}, which can't be used in an
initialization list.
On Win32 pthread_cond_t is a pointer to an incomplete type.
Local coding standards say I should initialize the compound in the
initialization list.
Is this possible without doing, say the following:
namespace {
static const pthread_cond_t
pthread_cond_intializer = PTHREAD_COND_INTIALIZER;
}
C::C ()
: m_cond(pthread_cond_intializer)
{}
Will it be possible in C++0x?
(Yes, I know boost::thread...
It was an exercise, more than anything else.)