pthread_exit((void *)0)

Hi,I'm Woods!
the function pthread_exit
void pthread_exit(void *rval_ptr);
will let the controlling thread exit with return value rval_ptr whose type is void *.

And then we can get the return value by the function pthread_join
int pthread_join(pthread_t thread,void **rval_ptr)

So,if we do like this ,it is easy to understand
in thread id=tid1
code:
int i;
i=1;
pthread_exit((void *)&i);
in main thread
code:
int *iret;
pthread_join(tid1,(void *)&iret);
printf("the return value of the thread tid1 is %d\n",(int)*i);

but if we do like this in thread:
pthread_exit((void *)0);

and get the return value in main:
void *tret;
pthread_join(tid1,&tret);
printf("%d",(int)tret);

how to understand the pthread_exit((void *)0) expression and the procedure it does

somebody help :)
Last edited on
Don't pass the address of a local variable to pthread_exit. The local variable will be gone and the memory possibly reused, the value may have changed by the time you read it.

Don't pass zero to pthread_exit as you have done. Your printf attempts to dereference address zero; which, in your case, is an error.

Have you tried google for examples?
http://publib.boulder.ibm.com/iseries/v5r2/ic2928/index.htm?info/apis/users_18.htm
thanks,KBW
i forgot I used a local variable :int i;
i will see the examples.
Topic archived. No new replies allowed.