So, I am using C++11 and I made a class
Class C
{
private:
queue<std::int> s;
pthread_t x;
public:
C() {phthread_create(&x, NULL, d_q, NULL);
void log(int p); // pushes into q.
void* d_q(void* q); // this is a function which will pop s. assume s is thread safe.
}
The problem is the line pthread_create(&x, NULL, d_q, NULL)
. It gives me Error: Reference to non-static member must be called.
I get rid of this problem by making pthread_t x static
. But I dont want to do this because of 2 reasons:
- Creation of a thread with a static function means only 1 copy of the function.
- The thread is created in a constructor. I don't know what will happen if I create more than one objects of class C.
Can someone please give me a workaround?
Solved: Thanks for the help! Also, a very good advice is to prefer std::thread over pthread for future users!