Issue 144137
Summary [tsan] Error message and hang involving signals
Labels new issue
Assignees
Reporter tavianator
    The following test program:

```c
#include <errno.h>
#include <signal.h>
#include <stdatomic.h>
#include <sys/wait.h>
#include <unistd.h>

static atomic_int n = 0;

static void handler(int sig, siginfo_t *info, void *context) {
        int x = atomic_load_explicit(&n, memory_order_relaxed);
        while (!atomic_compare_exchange_weak_explicit(&n, &x, x + 1,
 memory_order_acquire, memory_order_relaxed)) {
        }
}

int main(void) {
        struct sigaction action = {
 .sa_sigaction = handler,
                .sa_flags = SA_RESTART | SA_SIGINFO,
        };
        sigemptyset(&action.sa_mask);
 sigaction(SIGPIPE, &action, NULL);

        pid_t pid = fork();

 if (pid > 0) {
                usleep(1000);
                kill(pid, SIGPIPE);
                waitpid(pid, NULL, 0);
        } else if (pid == 0) {
                while (atomic_load(&n) < 1) {
 usleep(1);
                }
        }

        return 0;
}
```

Reliably prints this message and hangs:

```console
$ clang -Wall -fsanitize=thread foo.c -o foo
$ ./fo
ThreadSanitizer: CHECK failed: tsan_interceptors_posix.cpp:2107 "((thr->slot)) != (0)" (0x0, 0x0) (tid=620758)
^C
$ clang --version
clang version 20.1.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to