Thanks for the quick reply, your post made me realise that I forgot to allocate memory for the pthread_t object. Just incase anyone is curious the solution was:
1 2 3 4 5 6 7 8
CThread::CThread()
{
//set default vars:
m_running = false;
//create a new pthread object:
m_threadHandle = (pthread_t*)malloc(sizeof(pthread_t));
}
I realise that by not malloc'ing it I don't have to worry about memory fragmentation, however, nearly every call within pthread requests a pointer to a pthread_t struct, therefore I find it much more clearer to just declare a pointer and then malloc that. Rather than using &m_threadHandle everywhere.
That really makes no sense to me. You are using dynamic memory when it is not needed. You are using malloc in a C++ program. You are not checking the return of malloc. You are not initializing the pointer in the member init list. You are not using an auto_ptr, which means you have to free() inside the destructor. Why submit yourself to such a huge bug farm when kbw's method is short, simple and works?