1 /* $NetBSD: once3.c,v 1.1 2005/07/16 23:02:11 nathanw Exp $ */
10 pthread_once_t once
= PTHREAD_ONCE_INIT
;
11 pthread_mutex_t mutex
= PTHREAD_MUTEX_INITIALIZER
;
14 void* threadfunc(void *);
16 void handler(int, siginfo_t
*, void *);
19 main(int argc
, char *argv
[])
24 printf("Test 3 of pthread_once() (test versus cancellation)\n");
26 act
.sa_sigaction
= handler
;
27 sigemptyset(&act
.sa_mask
);
28 act
.sa_flags
= SA_SIGINFO
;
29 sigaction(SIGALRM
, &act
, NULL
);
31 timerclear(&it
.it_value
);
32 it
.it_value
.tv_usec
= 500000;
33 timerclear(&it
.it_interval
);
34 setitimer(ITIMER_REAL
, &it
, NULL
);
36 pthread_mutex_lock(&mutex
);
37 pthread_create(&thread
, NULL
, threadfunc
, NULL
);
38 pthread_cancel(thread
);
39 pthread_mutex_unlock(&mutex
);
40 pthread_join(thread
, NULL
);
42 pthread_once(&once
, ofunc
);
45 timerclear(&it
.it_value
);
46 setitimer(ITIMER_REAL
, &it
, NULL
);
48 printf("Test succeeded\n");
56 pthread_mutex_t
*mu
= m
;
58 pthread_mutex_unlock(mu
);
72 pthread_mutex_lock(&mutex
);
73 pthread_cleanup_push(cleanup
, &mutex
);
74 pthread_once(&once
, ofunc
);
75 pthread_cleanup_pop(1);
81 handler(int sig
, siginfo_t
*info
, void *ctx
)
83 printf("Signal handler was called; main thread deadlocked in "