Sync usage with man page.
[netbsd-mini2440.git] / regress / lib / libpthread / conddestroy1 / conddestroy1.c
blob93dd619dd91de11868a43ae06ae42d44e4d60fac
1 /* $NetBSD: conddestroy1.c,v 1.1 2004/07/07 21:53:10 nathanw Exp $ */
3 /*
4 * XXX This test is bogus. IEEE Std 1003.1, 2004 Edition says:
6 * If a signal is delivered to a thread waiting for a condition
7 * variable, upon return from the signal handler the thread resumes
8 * waiting for the condition variable as if it was not interrupted,
9 * or it shall return zero due to spurious wakeup.
12 #include <signal.h>
13 #include <stdio.h>
14 #include <pthread.h>
15 #include <unistd.h>
17 void handler(int);
18 void *threadroutine(void *);
20 pthread_mutex_t mt;
21 pthread_cond_t cv;
23 void
24 handler(int sig)
26 /* Dummy */
27 return;
30 void *
31 threadroutine(void *arg)
33 sigset_t set;
35 sigemptyset(&set);
36 sigaddset(&set, SIGALRM);
38 pthread_sigmask(SIG_UNBLOCK, &set, NULL);
40 pthread_mutex_lock(&mt);
43 * Explicitly not a loop; we want to see if the cv is properly
44 * torn down in a spurious wakeup (generated here by SIGALRM).
46 pthread_cond_wait(&cv, &mt);
48 pthread_mutex_unlock(&mt);
50 return NULL;
53 int
54 main(void)
56 pthread_t th;
57 sigset_t set;
58 struct sigaction act;
60 printf("Testing CV teardown under spurious wakeups.\n");
62 sigfillset(&set);
64 pthread_sigmask(SIG_BLOCK, &set, NULL);
66 act.sa_handler = handler;
67 sigemptyset(&act.sa_mask);
68 act.sa_flags = 0;
70 sigaction(SIGALRM, &act, NULL);
72 pthread_mutex_init(&mt, NULL);
73 pthread_cond_init(&cv, NULL);
75 pthread_create(&th, NULL, threadroutine, NULL);
77 alarm(1);
79 pthread_join(th, NULL);
81 pthread_cond_destroy(&cv);
82 pthread_mutex_destroy(&mt);
84 printf("Passed.\n");
85 return 0;