7 /* Test that signal masks are respected while threads are running. */
8 volatile sig_atomic_t flag
;
9 volatile sig_atomic_t flag2
;
11 volatile pthread_t thr_usr1
;
12 volatile pthread_t thr_usr2
;
14 void handler1(int, siginfo_t
*, void *);
15 void handler2(int, siginfo_t
*, void *);
16 void *threadroutine(void *);
19 handler1(int sig
, siginfo_t
*info
, void *ctx
)
22 kill(getpid(), SIGUSR2
);
24 * If the mask is properly set, SIGUSR2 will not be handled
25 * by the current thread until this handler returns.
28 thr_usr1
= pthread_self();
32 handler2(int sig
, siginfo_t
*info
, void *ctx
)
37 thr_usr2
= pthread_self();
41 threadroutine(void *arg
)
44 kill(getpid(), SIGUSR1
);
48 printf("Success: Both handlers ran in order\n");
49 else if (flag
== 1 && flag2
== 1 && thr_usr1
!= thr_usr2
)
50 printf("Success: Handlers were invoked by different threads\n");
52 printf("Failure: flag=%d, flag2=%d, thr1=%p, thr2=%p\n",
53 (int)flag
, (int)flag2
, (void *)thr_usr1
, (void *)thr_usr2
);
67 act
.sa_sigaction
= handler1
;
68 sigemptyset(&act
.sa_mask
);
69 sigaddset(&act
.sa_mask
, SIGUSR2
);
70 act
.sa_flags
= SA_SIGINFO
;
72 ret
= sigaction(SIGUSR1
, &act
, NULL
);
74 printf("sigaction: %d\n", ret
);
78 act
.sa_sigaction
= handler2
;
79 sigemptyset(&act
.sa_mask
);
80 act
.sa_flags
= SA_SIGINFO
;
81 ret
= sigaction(SIGUSR2
, &act
, NULL
);
83 ret
= pthread_create(&thread
, NULL
, threadroutine
, NULL
);
85 printf("pthread_create: %d\n", ret
);
88 ret
= pthread_join(thread
, NULL
);
90 printf("pthread_join: %d\n", ret
);