Pthread_exit( ) et pthread( ) join

razuki Messages postés 242 Date d'inscription lundi 17 décembre 2007 Statut Membre Dernière intervention 5 décembre 2012 - 3 sept. 2009 à 18:15
deck_bsd Messages postés 1243 Date d'inscription jeudi 31 mars 2005 Statut Membre Dernière intervention 3 août 2016 - 4 sept. 2009 à 14:45
Bonjour,
j'aimerais savoir comment doit - on procéder pour récuperer par l'intérmédiaire de pthread_join(thread, val_ret) une valeur de retour envoyé par pthread_exit(val_ret). Dans mon cas la valeur à recuperer est un entier.

Voici les syntaxes exactes:
pthread_exit(void *retval);
pthread_join(pthread th, void  **thread_return);



Voici à peu près ce que je dois faire ( est ce que c'est correcte ? )


void *my_thread(void *vargp)
{
    int retval = 42
    pthread_exit(&retval);
}
int main()
{
    int *i;
    pthread_t tid;
    pthread_create(&tid, NULL, my_thread, NULL);
    pthread_join(tid, &i);
    printf("%d\n",i);
}


Merci d'avance pour votre aide

1 réponse

deck_bsd Messages postés 1243 Date d'inscription jeudi 31 mars 2005 Statut Membre Dernière intervention 3 août 2016 2
4 sept. 2009 à 14:45
Yop,

Comme ceci :

Imagine fctth est la fonction de ton thread :

void *fctth(int * param)
{
  static int retour = 88;


  pthread_ext(&retour);
}

// Le pthread_join sera :

ret = pthread_join(HandleThread,(void**)&retourfctth);




Tout simplement
++
deck_bsd
___________________________________
http://deck-bsd.eurower.net
0
Rejoignez-nous