You are not logged in.
I am trying to pass a routine to "pthread_create()" function, which returns an integer as its return value. I do not know how to access this returned value. Can you please help me?
here is the way I do the creation:
and the start is as this way:
Would you please write me the exact syntax of how this can be done? now I assign the pthread_join return value to an integer but it is zero.
and further more changing the (void*)start to (int)(void*)start results in warnings.
According to your guidance and the man page of pthread_join now I do the following:
but now that I print r there is not the desired result. it is a big numbet such as -2375165318376
wow!it is working now.
in the start I simply write it this way:
return (void*) counter;
and in main:
pthread_join(tid, (void*) & counter);
and it is perfect now.
Your last problem, before you fixed it, was that 'counter' is allocated on the
stack and disappears when the function exits.
Well, that and the fact he was printing the pointer value instead of dereferencing it,
I'd assume... The way he's doing it now, it doesn't need dereferencing, of course,
because it's just using the pointer to hold an int value...
However, this will be a problem if you ever compile on a 64-bit platform:
int counter; pthread_join(tid, (void*) & counter);
You'll trash 4 bytes of your stack with that on a 64-bit system, because void* will be
a 64-bit value and int will only be 32-bit... You really should use a void* variable,
and then cast that back to int after filling it in...