Expand PMF_FN_* macros.
[netbsd-mini2440.git] / regress / lib / libpthread / once2 / once2.c
blob74a6b4318759e2492b50a43192bae8aba899282e
1 /* $NetBSD$ */
3 #include <assert.h>
4 #include <err.h>
5 #include <pthread.h>
6 #include <stdio.h>
7 #include <stdlib.h>
9 pthread_once_t once = PTHREAD_ONCE_INIT;
10 static int x;
12 #define NTHREADS 25
14 void ofunc(void);
15 void* threadfunc(void *);
17 int
18 main(int argc, char *argv[])
20 pthread_t threads[NTHREADS];
21 int id[NTHREADS];
22 int i;
24 printf("1: Test 2 of pthread_once()\n");
26 for (i=0; i < NTHREADS; i++) {
27 id[i] = 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 );
35 assert(x == 2);
37 return 0;
41 void
42 ofunc(void)
44 x++;
45 printf("ofunc: Variable x has value %d\n", x);
46 x++;
49 void *
50 threadfunc(void *arg)
52 int num;
54 pthread_once(&once, ofunc);
56 num = *(int *)arg;
57 printf("Thread %d sees x with value %d\n", num, x);
58 assert(x == 2);
60 return NULL;