Skip to content

Commit 79dbccd

Browse files
issue/461 make current runtime thread local (#503)
2 parents acb75f3 + 0bb940d commit 79dbccd

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/infinicore/context/context_impl.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace infinicore {
66

7+
thread_local Runtime *ContextImpl::current_runtime_ = nullptr;
8+
79
Runtime *ContextImpl::getCurrentRuntime() {
810
return current_runtime_;
911
}

src/infinicore/context/context_impl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
namespace infinicore {
99
class ContextImpl {
1010
private:
11+
// Table of runtimes for every device (type and index)
1112
std::array<std::vector<std::unique_ptr<Runtime>>, size_t(Device::Type::COUNT)> runtime_table_;
12-
Runtime *current_runtime_ = nullptr;
13+
// Active runtime for current thread. Can use "static thread local" because context is a process singleton.
14+
static thread_local Runtime *current_runtime_;
1315

1416
protected:
1517
ContextImpl();

0 commit comments

Comments
 (0)