Files
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

80 lines
2.0 KiB
C++

// RUN: %clang_tsan %s -lstdc++ -o %t && %run %t 2>&1 | FileCheck %s
#include "test.h"
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <atomic>
#include <cassert>
#include <condition_variable>
#include <mutex>
std::mutex sampler_mutex; //dummy mutex to lock in the thread we spawn.
std::mutex done_mutex; // guards the cv and done variables.
std::condition_variable cv;
bool done = false;
std::atomic<bool> spin = true;
void *ThreadFunc(void *x) {
while (spin) {
// Lock the mutex
std::lock_guard<std::mutex> guard(sampler_mutex);
// Mutex is released at the end
}
return nullptr;
}
static void SigprofHandler(int signal, siginfo_t *info, void *context) {
// Assuming we did some work, change the variable to let the main thread
// know that we are done.
{
std::unique_lock<std::mutex> lck(done_mutex);
done = true;
cv.notify_one();
}
}
int main() {
alarm(60); // Kill the test if it hangs.
// Install the signal handler
struct sigaction sa;
sa.sa_sigaction = SigprofHandler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
if (sigaction(SIGPROF, &sa, 0) != 0) {
fprintf(stderr, "failed to install signal handler\n");
abort();
}
// Spawn a thread that will just loop and get the mutex lock:
pthread_t thread;
pthread_create(&thread, NULL, ThreadFunc, NULL);
{
// Lock the mutex before sending the signal
std::lock_guard<std::mutex> guard(sampler_mutex);
// From now on thread 1 will be waiting for the lock
// Send the SIGPROF signal to thread.
int r = pthread_kill(thread, SIGPROF);
assert(r == 0);
// Wait until signal handler sends the data.
std::unique_lock lk(done_mutex);
cv.wait(lk, [] { return done; });
// We got the done variable from the signal handler. Exiting successfully.
fprintf(stderr, "PASS\n");
}
// Wait for thread to prevent it from spinning on a released mutex.
spin = false;
pthread_join(thread, nullptr);
}
// CHECK-NOT: WARNING: ThreadSanitizer:
// CHECK: PASS