Answer the question
In order to leave comments, you need to log in
Lambda Callback from Pthread?
The task is to pass a function to the lambda thread to handle, for example, the thread completion event (onload, or maybe onprogress).
I do it like this:
struct Arg {
void (*func)();
};
void* threadFunction(void *arg) {
((Arg*) arg)->func();
}
void Network::open(const char * url, void (*onload)()) {
Arg* arg;
arg->func = onload; /// сюда передается какая-то лямбда из внешнего метода []() { };
pthread_attr_init(&attr);
rc = pthread_create(&thread[0], &attr, threadFunction, arg);
if (rc) {
Logger::log("ERROR; return code from pthread_create() is %d\n", rc);
return;
}
pthread_attr_destroy(&attr);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question