if there is function for thread creating
int thread_create( void*(*create_cb)(void*), void* arg);
there is a class example which have a member function:
void* example::startupTask(void *args);
how to convert to "C" format by using std::bind member function of a class as a thread portal function?
std::function<void* (void*)> func = std::bind(&example::startupTask, this, std::placeholders::_1);
auto rtn = thread_create((*func.target<std::_Bind <void*(example::*(example*, std::_Placeholder<1>))(void*)> >()), nullptr);
this code can run crashed.
Impossible. std::bind
returns a CPP object with operator()
, so it acts like a function. thread_create
expects a pointer to a memory address.
Instead, you should use the additional parameter in thread_create
to pass the context for the function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.