c++ - pthread_create - invalid use of non-static member function -
this question has answer here:
- pthread function class 7 answers
i've been trying learn how use threads, , i'm getting stuck on creating one. i'm having thread created in class constructor this...
beacon::beacon() { pthread_create(&send_thread,null, send, null); }
the send function isn't doing yet, here's looks like.
void beacon::send(void *arg){ //do stuff }
everytime run code invalid use of non-static member funciton error. i've tried using &send, , didn't work. had last null parameter set this, didn't work. i've been looking @ other example code try , mimmick it, nothing seems work. doing wrong?
if can't use std::thread
recommend create static
member function wrap actual function, , pass this
argument function.
something like
class beacon { ... static void* send_wrapper(void* object) { reinterpret_cast<beacon*>(object)->send(); return 0; } };
then create thread like
pthread_create(&send_thread, null, &beacon::send_wrapper, this);
Comments
Post a Comment