I have the following encapsulation for my pthread_t
threads:
#include <pthread.h>
class Thread
{
public:
void run(const int);
static void *run_helper(void *);
bool startThread(int);
void joinThread();
pthread_t th;
};
Where run
is my thread routine, and run_helper
is the following:
void *Thread::run_helper(int num)
{
return (Thread *)this->run(num);
}
I start my threads like such:
bool Thread::startThread(intptr_t arg)
{
return (pthread_create(&this->th, NULL, &run_helper(arg), (void *)(intptr_t)arg));
}
But when I compile, I get the following errors:
error: lvalue required as unary ‘&’ operand return (pthread_create(&this->th, NULL, &run_helper(arg), (void *)(intptr_t)arg));
error: ‘this’ is unavailable for static member functions return (Thread *)this->run(num);
And despite trying, I can't seem to make this encapsulation work.