c - How is exit status passed between pthread_exit and pthread_join? Is a correction needed in man page? -


question:

how exit status passed between pthread_exit , pthread_join?

from pthread_join man page

   int pthread_join(pthread_t thread, void **retval); 

if retval not null, pthread_join() copies exit status of target thread (i.e., value target thread supplied pthread_exit(3)) location pointed *retval. if target thread canceled, pthread_canceled placed in *retval.

i think wording in man page incorrect.

it should "if retval not null, pthread_join() copies address of variable holding exit status of target thread (i.e., value target thread supplied pthread_exit(3)) location pointed retval."

i wrote code shows this, see code comments:

#include<stdio.h> #include<stdlib.h> #include<pthread.h>  void * function(void*);  int main() {     pthread_t thread;     int arg = 991;     int * status; // notice did not intialize status, status *retval     pthread_create(&thread, null, function, (void*)(&arg));      pthread_join(thread, (void **)(&status));//passing address of status,&status retval       //(2) address same printed in (1)     printf("the address of returned status %p,", status);       printf("the returned status %d\n", *status); }  void * function(void * arg) {     int *p;     p = (int*)arg;     printf("i in thread.\n");       //(1) printing address of variable holding exit status of thread, see (2)                                                                   printf("the arg address %p %p\n", p, arg);       pthread_exit(arg); } 

sample o/p:

i in thread.

the arg address 0xbfa64878 0xbfa64878

the address of returned status 0xbfa64878,the returned status 991***

your code doesn't contradict man page.

if retval not null, pthread_join() copies exit status of target thread (i.e., value target thread supplied pthread_exit(3)) location pointed *retval.

you call pthread_join retval=&status, it's not null.

you called pthread_exit(0xbfa64878) exit status of target thread 0xbfa64878 , gets copied *retval i.e. status = 0xbfa64878, print out.

i think you're confusing things labels such "address of returned status" , "arg address" ... you're giving labels values pthreads doesn't imply. man page says *retval gets set value passed pthread_exit , that's test shows.

in proposed change:

if retval not null, pthread_join() copies address of variable holding exit status of target thread (i.e., value target thread supplied pthread_exit(3)) location pointed retval.

what "the variable holding exit status of target thread"? pthreads defines no such thing. exit status of target thread is value passed pthread_exit, it's not value of other variable.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -