From 0bb940db987be879e42bf687e28cf62378c7a4cb Mon Sep 17 00:00:00 2001 From: PanZezhong1725 Date: Mon, 13 Oct 2025 17:03:39 +0800 Subject: [PATCH] issue/461 make current runtime thread local --- src/infinicore/context/context_impl.cc | 2 ++ src/infinicore/context/context_impl.hpp | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/infinicore/context/context_impl.cc b/src/infinicore/context/context_impl.cc index de84f2daa..b565ecef4 100644 --- a/src/infinicore/context/context_impl.cc +++ b/src/infinicore/context/context_impl.cc @@ -4,6 +4,8 @@ namespace infinicore { +thread_local Runtime *ContextImpl::current_runtime_ = nullptr; + Runtime *ContextImpl::getCurrentRuntime() { return current_runtime_; } diff --git a/src/infinicore/context/context_impl.hpp b/src/infinicore/context/context_impl.hpp index 8a63d5cf9..ea9fbae66 100644 --- a/src/infinicore/context/context_impl.hpp +++ b/src/infinicore/context/context_impl.hpp @@ -8,8 +8,10 @@ namespace infinicore { class ContextImpl { private: + // Table of runtimes for every device (type and index) std::array>, size_t(Device::Type::COUNT)> runtime_table_; - Runtime *current_runtime_ = nullptr; + // Active runtime for current thread. Can use "static thread local" because context is a process singleton. + static thread_local Runtime *current_runtime_; protected: ContextImpl();