/* * programa exemplo */ #include #include #include #include volatile int s = 0; /* Variavel compartilhada */ void* f_thread(void *v) { int thr_id; thr_id = (int) v; s = thr_id; printf("Thread %d, s = %d.\n", thr_id,s); return NULL; } int main() { pthread_t thr[10]; int i; for(i=0;i<10;i++) pthread_create(&thr[i], NULL, f_thread, (void*)i); for(i=0;i<10;i++) pthread_join(thr[i], NULL); return 0; }