Do not do that. Use boost::thread.
With the help of boost::threadyou can start threads with any signature functor void(), so you can use std::mem_funand std::bind1st, for example, in
struct MyAwesomeThread
{
void operator()()
{
}
private:
};
MyAwesomeThread t(parameters)
boost::thread(std::bind1st(std::mem_fun_ref(&t::operator()), t));
EDIT: If you really want to abstract POSIX threads (it's not complicated), you can do (I leave you with pthread_attr initialization)
class thread
{
virtual void run() = 0;
static void run_thread_(void* ptr)
{
reinterpret_cast<thread*>(ptr)->run();
}
pthread_t thread_;
pthread_attr_t attr_;
public:
void launch()
{
pthread_create(&thread_, &attr_, &::run_thread_, reinterpret_cast<void*>(this));
}
};
but it boost::threadis portable, flexible and very easy to use.
source
share