/* * Cada thread tem um identificador único. Vamos * verificar os endereços das pilhas de execução. */ #include #include #include #include void* f_thread(void *v) { int thr_id; sleep(1); thr_id = *(int *) v; printf("Thread %d. Endereço de thr_id: %x \n", thr_id, (int) &thr_id); return NULL; } int main() { pthread_t thr[10]; int i, id[10]; for (i = 0; i < 10; i++) { id[i] = i; pthread_create(&thr[i], NULL, f_thread, (void*) &id[i]); } for (i = 0; i < 10; i++) pthread_join(thr[i], NULL); return 0; }