Add clear_streams API for cleanup before exit (#3395)

This commit is contained in:
Cheng
2026-04-14 18:41:32 +09:00
committed by GitHub
parent 520cea2bec
commit 435f0b6cdb
10 changed files with 53 additions and 3 deletions
+20 -2
View File
@@ -48,8 +48,11 @@ TEST_CASE("test default stream in threads") {
for (size_t i = 0; i < num_threads; ++i) {
threads.emplace_back([&thread_streams, &mtx]() {
auto s = default_stream(gpu::is_available() ? Device::gpu : Device::cpu);
std::lock_guard lock(mtx);
thread_streams.insert(s);
{
std::lock_guard lock(mtx);
thread_streams.insert(s);
}
clear_streams();
});
}
@@ -80,12 +83,27 @@ TEST_CASE("test access stream in other thread") {
} catch (const std::runtime_error&) {
error_caught = true;
}
clear_streams();
});
t.join();
CHECK(error_caught);
}
TEST_CASE("test new stream in threads") {
std::vector<std::thread> threads;
for (int i = 0; i < 1; ++i) {
threads.emplace_back([]() {
auto s = new_stream(default_device());
eval(arange(10, s));
clear_streams();
});
}
for (auto& t : threads) {
t.join();
}
}
TEST_CASE("test get streams") {
// Initialize default CPU stream before querying
default_stream(Device::cpu);