In pthread:
#include "pthread.h"
class Reader { // Class to spawn ReadThread
public:
void ReadBuffer();
private:
void ReadThread();
static void *_ReadThread(void*);
};
void Reader::ReadBuffer() {
pthread_t thread;
pthread_create(&thread, NULL, _ReadThread, (void *) this);
}
void *Reader::_ReadThread(void *ptr) {
Reader *that=(Reader )ptr;
that->ReadThread();
return(0);
};
void Reader::ReadThread() {//your thread function
}
In Boost::Thread:
#include "boost/thread/thread.hpp"
#include "boost/bind.hpp"
public:
void ReadBuffer();
private:
void ReadThread(int id); // boost thread
};
void Reader::ReadBuffer() {
int threadID;
boost::thread readThrd(boost::bind(&Reader::ReadThread, this, threadID);
}
void Reader::ReadThread() {//your thread function
}
Boost::Thread is also crossplatform and very neatly OO-programmed.
Why multithread ?