Files
TheRock/compiler/amd-llvm/libcxx/test/std/atomics/atomics.ref/notify_all.pass.cpp
T
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

79 lines
2.1 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: no-threads
// XFAIL: !has-64-bit-atomics
// XFAIL: !has-1024-bit-atomics
// void notify_all() const noexcept;
#include <atomic>
#include <cassert>
#include <thread>
#include <type_traits>
#include <vector>
#include "atomic_helpers.h"
#include "make_test_thread.h"
#include "test_macros.h"
template <typename T>
struct TestNotifyAll {
void operator()() const {
alignas(std::atomic_ref<T>::required_alignment) T x(T(1));
std::atomic_ref<T> const a(x);
bool done = false;
std::atomic<int> started_num = 0;
std::atomic<int> wait_done_num = 0;
constexpr auto number_of_threads = 8;
std::vector<std::thread> threads;
threads.reserve(number_of_threads);
for (auto j = 0; j < number_of_threads; ++j) {
threads.push_back(support::make_test_thread([&a, &started_num, &done, &wait_done_num] {
started_num.fetch_add(1, std::memory_order::relaxed);
a.wait(T(1));
wait_done_num.fetch_add(1, std::memory_order::relaxed);
// likely to fail if wait did not block
assert(done);
}));
}
while (started_num.load(std::memory_order::relaxed) != number_of_threads) {
std::this_thread::yield();
}
std::this_thread::sleep_for(std::chrono::milliseconds(1));
done = true;
a.store(T(3));
a.notify_all();
// notify_all should unblock all the threads so that the loop below won't stuck
while (wait_done_num.load(std::memory_order::relaxed) != number_of_threads) {
std::this_thread::yield();
}
for (auto& thread : threads) {
thread.join();
}
ASSERT_NOEXCEPT(a.notify_all());
}
};
int main(int, char**) {
TestEachAtomicType<TestNotifyAll>()();
return 0;
}