Sync usage with man page.
[netbsd-mini2440.git] / regress / lib / libpthread / sigmask4 / sigmask4.c
blob17fe36026af6da92fb8e8bf034dac3c576e0cd5e
1 /*
2 * Create a thread that is running [the sleeper] with a signal blocked
3 * and use the other thread to block on select. This is so that we can
4 * send the signal on the "select" thread. Interrupt the selected thread
5 * with alarm. Detects bug in libpthread where we did not use the proper
6 * signal mask, so only the first signal got delivered.
7 */
8 #include <signal.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <err.h>
12 #include <errno.h>
13 #include <pthread.h>
15 static sig_atomic_t count = 0;
17 static void
18 handler(int sig)
20 count++;
23 static void *
24 sleeper(void* arg)
26 int i;
27 for (i = 0; i < 10; i++)
28 sleep(1);
29 exit(1);
32 int
33 main(int argc, char** argv)
35 pthread_t id;
36 struct sigaction act;
38 act.sa_sigaction = NULL;
39 sigemptyset(&act.sa_mask);
40 act.sa_flags = 0;
41 act.sa_handler = handler;
43 if (sigaction(SIGALRM, &act, NULL) == -1)
44 err(1, "sigaction");
46 sigaddset(&act.sa_mask, SIGALRM);
47 pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL);
49 pthread_create(&id, NULL, sleeper, NULL);
50 sleep(1);
52 sigemptyset(&act.sa_mask);
53 pthread_sigmask(SIG_SETMASK, &act.sa_mask, NULL);
55 for (;;) {
56 alarm(1);
57 if (select(1, NULL, NULL, NULL, NULL) == -1 && errno == EINTR)
58 if (count == 2)
59 return 0;