static void *myfun (void *arg){
int exitvalue = 17;
pthread_exit(&exitvalue);
}
int main (void) {
int i,status;
pthread tid[N];
void *ret;
for(i = 0; i < N; i++)
pthread_create(&tid[i], NULL, &myfun, &i);
for(i = 0; i < N; i++){
pthread_join(tid[i], &ret);
status = *(int *) ret;
printf("Thread #%d ends: %d status\n",i,status);
}
Per N = 10 mi da questo output
Thread #0 ends: 1 status
Thread #1 ends: 1 status
Thread #2 ends: 1582507208 status
Thread #3 ends: 1 status
Thread #4 ends: 1 status
Thread #5 ends: 1 status
Thread #6 ends: 1582507208 status
Thread #7 ends: 1582507208 status
Thread #8 ends: 1 status
Thread #9 ends: 1 status
Ma gli status dovrebbero essere tutti 17.