/* * Criação de uma nova thread, com envio de valor de retorno. */ #include #include #include typedef struct { int id; int status; } Retorno; void* f_thread(void *v) { int thr_id = *(int *) v; Retorno* p_retorno = (Retorno*) malloc (sizeof(Retorno)); printf("Thread %d.\n", thr_id); p_retorno->id = thr_id; p_retorno->status = 0; /* OK */ return (void*) p_retorno; } int main() { pthread_t thr; int thr_id = 1; Retorno* p_retorno; pthread_create(&thr, NULL, f_thread, (void*) &thr_id); pthread_join(thr, (void**) &p_retorno); printf("Valor de retorno: id = %d e status = %d\n", p_retorno->id, p_retorno->status); free(p_retorno); return 0; }