/* ================================================================= Thread example: thread join, returning a value ================================================================= */ #include #include #include extern "C" void * my_proc(void *arg) { int output; output = 1234; pthread_exit( (void *) &output ); return(NULL); } /* ======================= MAIN ======================= */ int main(int argc, char *argv[]) { pthread_t TID; /* Thread ID used for thread_join() */ int *out; if ( pthread_create(&TID, NULL, my_proc, NULL) != NULL ) { cout << "Cannot create thread" << endl; exit(1); } pthread_join(TID, (void * *) &out ); cout << "Thread return this value: " << *out << endl; }