9 pthread_once_t once
= PTHREAD_ONCE_INIT
;
15 void* threadfunc(void *);
18 main(int argc
, char *argv
[])
20 pthread_t threads
[NTHREADS
];
24 printf("1: Test 2 of pthread_once()\n");
26 for (i
=0; i
< NTHREADS
; i
++) {
28 pthread_create(&threads
[i
], NULL
, threadfunc
, &id
[i
]);
31 for (i
=0; i
< NTHREADS
; i
++)
32 pthread_join(threads
[i
], NULL
);
34 printf("1: X has value %d\n",x
);
45 printf("ofunc: Variable x has value %d\n", x
);
54 pthread_once(&once
, ofunc
);
57 printf("Thread %d sees x with value %d\n", num
, x
);