1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // Test that a signal is not delivered when it is blocked.
11 sig_atomic_t signal_blocked
;
13 void handler(int signum
) {
15 fprintf(stderr
, "signal arrived when blocked\n");
20 void *thread(void *arg
) {
23 sigaddset(&myset
, SIGUSR1
);
24 while (!__atomic_load_n(&stop
, __ATOMIC_RELAXED
)) {
26 if (pthread_sigmask(SIG_BLOCK
, &myset
, 0)) {
27 fprintf(stderr
, "pthread_sigmask failed %d\n", errno
);
33 if (pthread_sigmask(SIG_UNBLOCK
, &myset
, 0)) {
34 fprintf(stderr
, "pthread_sigmask failed %d\n", errno
);
41 int main(int argc
, char** argv
) {
42 struct sigaction act
= {};
43 act
.sa_handler
= &handler
;
44 if (sigaction(SIGUSR1
, &act
, 0)) {
45 fprintf(stderr
, "sigaction failed %d\n", errno
);
49 pthread_create(&th
, 0, thread
, 0);
50 for (int i
= 0; i
< 100000; i
++)
51 pthread_kill(th
, SIGUSR1
);
52 __atomic_store_n(&stop
, 1, __ATOMIC_RELAXED
);
54 fprintf(stderr
, "DONE\n");
58 // CHECK-NOT: ThreadSanitizer CHECK
59 // CHECK-NOT: WARNING: ThreadSanitizer: