Skip to content

[tsan] Error message and hang involving signals #144137

Open
@tavianator

Description

@tavianator

The following test program:

#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:

$ clang -Wall -fsanitize=thread foo.c -o foo
$ ./foo
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions