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();