I am currently working on a some C code, very new to C, so apologize if this is a bit basic or a stupid question.
I have the following code which is executed within a thread using pthread_create().
if (ps.status == completed)
{
LOG(LOG_AUDIO, "evsafewait_sm_play_tone:\tPlay tone complete");
if (e2)
{
LOG(LOG_MUST, "Failed to free tone event. Result: %i", e2);
}
pccb->playToneComplete = 1;
LOG(LOG_AUDIO, "Detatching thread ID %x", manageToneParms->toneManagerThread);
//pthread_detach(manageToneParms->toneManagerThread);
int retVal;
pthread_exit(&retVal);
LOG(LOG_AUDIO, "THREAD TERMINATED WITH RESULT %i", retVal);
LOG(LOG_AUDIO, "Freeing memory");
free(manageToneParms->playToneParms);
free(manageToneParms);
return 0;
}
Before the structures are free and the method returns I am trying to exit the thread using pthread_exit() but when this is called, everything below it is skipped, no errors are displayed, as far as I can see anyway.
I have tried debugging it with GDB and when pthread_exit() is called the next thing it prints out is siglongjmp, I have no idea what this is, I don’t believe it’s in the C code, at least not in the changes that I have been making to it.
How can I exit this thread? I’ve also tried pthread_exit(NULL) and pthread_kill(threadID, SIGKILL) but then this kills the whole program not just the thread.
pthread_exit()returns from the thread at the point of the call. Any code afterpthread_exit()will not be executed.You should be sure to release any memory allocated in the thread before calling
pthread_exit().Have you tried something like this:?