I’m trying to get a function to start up another thread, and then return, with the thread still running. It seems like pthread_detach() would take care of the memory and whatnot for me, although I’m not entirely sure. This is the code for the function:
void function() {
pthread_mutex_lock(&state.continueLoopingMutex);
if(state.continueLooping == true) {
pthread_mutex_unlock(&state.continueLoopingMutex);
return;
}
state.continueLooping = true;
pthread_mutex_unlock(&state.continueLoopingMutex);
pthread_t thread;
pthread_create(&thread, NULL, runLoop, NULL);
pthread_detach(thread);
}
(The loop will stop when continueLooping is set to false, once the loop finishes it just returns without doing anything else).
Is there anything wrong with this structure that would cause a memory leak, etc., that I should care about?
Thank you
I don’t see anything wrong.
Yes the
pthread_detachwill take care to release the resources of the thread.