pthread_exit vs. return
Eu tenho uma função de junção pthread runner definida como abaixo:
void *sumOfProducts(void *param)
{
...
pthread_exit(0);
}
Este tópico deve se juntar ao tópico principal.
Sempre que eu executava meu programa através do Valgrind, recebia oseguintes vazamentos:
LEAK SUMMARY:
definitely lost: 0 bytes in 0 blocks
indirectly lost: 0 bytes in 0 blocks
possibly lost: 0 bytes in 0 blocks
still reachable: 968 bytes in 5 blocks
suppressed: 0 bytes in 0 blocks
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 10)
Eu verifiquei a página de manual em busca de pthreads, que dizia:
The new thread terminates in one of the following ways:
* It calls pthread_exit(3), specifying an exit status value that is
available to another thread in the same process that calls
pthread_join(3).
* It returns from start_routine(). This is equivalent to calling
pthread_exit(3) with the value supplied in the return statement.
* It is canceled (see pthread_cancel(3)).
* Any of the threads in the process calls exit(3), or the main thread
performs a return from main(). This causes the termination of all
threads in the process.
Milagrosamente, quando substituí o pthread_exit () por uma declaração de retorno,os vazamentos desapareceram.
return(NULL);
Minha pergunta real é tripla:
Alguém pode explicar por que a declaração de retorno não deu vazamentos?Existe alguma diferença fundamental entre as duas instruções, em relação à saída de threads?Em caso afirmativo, quando um deve ser preferido em detrimento do outro?