You are not logged in.
Pages: 1
Hi,
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:
///////////////////////////////
int status;
pthread_t tid;
status=pthread_create(&tid,NULL,(void*)start,NULL);
and the start is as this way:
int start()
{
int count=10;
return count;
}
/////////////////////////////////////
Offline
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.
Offline
According to your guidance and the man page of pthread_join now I do the following:
void* start()
{
int counter;
counter=10;
pthread_exit(&counter);
}
main()
{
void* r;
....
pthread_join(tid,&r);
....
}
but now that I print r there is not the desired result. it is a big numbet such as -2375165318376
Offline
wow!it is working now.
in the start I simply write it this way:
void* start()
{
int counter=10;
return (void*) counter;
}
and in main:
...
int counter;
pthread_join(tid, (void*) & counter);
and it is perfect now.
..
Offline
Pages: 1