]>
git.saurik.com Git - apple/libpthread.git/blob - tests/once.c
1 #define __DARWIN_NON_CANCELABLE 0
7 static pthread_once_t once
= PTHREAD_ONCE_INIT
;
12 printf("thread cancelled.\n");
17 printf("in once handler: %p\n", pthread_self());
24 printf("a started: %p\n", pthread_self());
25 pthread_cleanup_push((void*)cancelled
, NULL
);
26 pthread_once(&once
, oncef
);
27 pthread_cleanup_pop(0);
28 printf("a finished\n");
34 sleep(1); // give enough time for a() to get into pthread_once
35 printf("b started: %p\n", pthread_self());
36 pthread_once(&once
, oncef
);
37 printf("b finished\n");
44 if (pthread_create(&t1
, NULL
, a
, NULL
) != 0) {
45 fprintf(stderr
, "failed to create thread a.");
50 if (pthread_create(&t2
, NULL
, b
, NULL
) != 0) {
51 fprintf(stderr
, "failed to create thread b.");
58 pthread_join(t1
, NULL
);
59 pthread_join(t2
, NULL
);