pthread_exit vs retour

J'ai un recrutables pthread coureur de la fonction définie comme ci-dessous:

void *sumOfProducts(void *param)
{
...
pthread_exit(0);
}

Ce fil est censé rejoindre le thread principal.

Chaque fois que j'ai couru mon programme par le biais de Valgrind, je voudrais obtenir le suite à des fuites:

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)

J'ai vérifié la page de man pour les pthreads qui a dit:

  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.

Miraculeusement, quand j'ai remplacé le pthread_exit() avec une instruction de retour, les fuites disparu.

return(NULL);

Ma réelle question est de trois volets:

  1. Quelqu'un peut m'expliquer pourquoi l'instruction return a donné aucune fuite?
  2. Est-il une différence fondamentale entre les deux états, en ce qui concerne la sortie de threads?
  3. Si oui, où doit-on la préférence sur les autres?
  • Êtes-vous vraiment à l'aide de C++? C++ utilise portée pour détruire les objets et le retour de "laisser" que la portée de tout pthread_exit ne sera pas.
  • Je suis désolé, mais je n'ai jamais mentionner le C++ n'importe où dans ma question. Je suis de tout faire en C à partir de maintenant.
  • Je sais que tu ne l'ai pas mentionné, mais c'était une supposition, c'est pourquoi j'ai demandé. 🙂 Pourriez-vous fournir un ensemble de test cas?
InformationsquelleAutor | 2010-10-02