hot to get a return value from a function executed by a pthread
hi all,
i want to execute a function by a separate thread and get that functions return value in to the main thread.
one way to do this is set a global variable by that separate thread and access that variable from the main thread. This procedure is as follow.
int tid = 0; // global variable
void *PrintHello(void *threadid)
{
tid = (int)threadid;
// set the global variable by a separate thread
}
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
int rc, t;
for(t=0; t
rpjanaka
Junior Poster in Training
69 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
Look up pthread_exit() and pthread_join() for ways of communicating information from the thread back to the parent.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953