CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
98 lines
2.3 KiB
C
98 lines
2.3 KiB
C
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t > %t.out
|
|
// RUN: FileCheck %s --check-prefixes=CHECK,PARENT --input-file %t.out
|
|
// RUN: FileCheck %s --check-prefixes=CHECK,CHILD --input-file %t.out
|
|
// Regression test for
|
|
// https://groups.google.com/g/thread-sanitizer/c/TQrr4-9PRYo/m/HFR4FMi6AQAJ
|
|
#include "test.h"
|
|
#include <errno.h>
|
|
#include <signal.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
|
|
long glob = 0;
|
|
|
|
void *worker(void *main) {
|
|
glob++;
|
|
// synchronize with main
|
|
barrier_wait(&barrier);
|
|
// synchronize with atfork
|
|
barrier_wait(&barrier);
|
|
pthread_kill((pthread_t)main, SIGPROF);
|
|
barrier_wait(&barrier);
|
|
// synchronize with afterfork
|
|
barrier_wait(&barrier);
|
|
pthread_kill((pthread_t)main, SIGPROF);
|
|
barrier_wait(&barrier);
|
|
return NULL;
|
|
}
|
|
|
|
void atfork() {
|
|
write(2, "in atfork\n", strlen("in atfork\n"));
|
|
barrier_wait(&barrier);
|
|
barrier_wait(&barrier);
|
|
static volatile long a;
|
|
__atomic_fetch_add(&a, 1, __ATOMIC_RELEASE);
|
|
}
|
|
|
|
void afterfork() {
|
|
write(2, "in afterfork\n", strlen("in afterfork\n"));
|
|
barrier_wait(&barrier);
|
|
barrier_wait(&barrier);
|
|
static volatile long a;
|
|
__atomic_fetch_add(&a, 1, __ATOMIC_RELEASE);
|
|
}
|
|
|
|
void afterfork_child() {
|
|
write(2, "in afterfork_child\n", strlen("in afterfork_child\n"));
|
|
glob++;
|
|
}
|
|
|
|
void handler(int sig) {
|
|
write(2, "in handler\n", strlen("in handler\n"));
|
|
glob++;
|
|
}
|
|
|
|
int main() {
|
|
barrier_init(&barrier, 2);
|
|
struct sigaction act = {};
|
|
act.sa_handler = &handler;
|
|
if (sigaction(SIGPROF, &act, 0)) {
|
|
perror("sigaction");
|
|
exit(1);
|
|
}
|
|
pthread_atfork(atfork, afterfork, afterfork_child);
|
|
pthread_t t;
|
|
pthread_create(&t, NULL, worker, (void *)pthread_self());
|
|
barrier_wait(&barrier);
|
|
pid_t pid = fork();
|
|
if (pid < 0) {
|
|
fprintf(stderr, "fork failed: %d\n", errno);
|
|
return 1;
|
|
}
|
|
if (pid == 0) {
|
|
fprintf(stderr, "CHILD\n");
|
|
return 0;
|
|
}
|
|
if (pid != waitpid(pid, NULL, 0)) {
|
|
fprintf(stderr, "waitpid failed: %d\n", errno);
|
|
return 1;
|
|
}
|
|
pthread_join(t, NULL);
|
|
fprintf(stderr, "PARENT\n");
|
|
return 0;
|
|
}
|
|
|
|
// CHECK: in atfork
|
|
// CHECK: in handler
|
|
// CHECK: ThreadSanitizer: data race
|
|
// CHECK: Write of size 8
|
|
// CHECK: #0 handler
|
|
// CHECK: Previous write of size 8
|
|
// CHECK: #0 worker
|
|
// PARENT: afterfork
|
|
// PARENT: in handler
|
|
// CHILD: afterfork_child
|
|
// CHILD: CHILD
|
|
// CHECK: PARENT
|