From c85e13796a0fd8060b9e53b03164e1e02bf6ddac Mon Sep 17 00:00:00 2001 From: lin-hitonami Date: Wed, 9 Nov 2022 14:21:36 +0800 Subject: [PATCH] fix --- taichi/program/program.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/taichi/program/program.h b/taichi/program/program.h index a8ccb3a43c7b0..39606aa426715 100644 --- a/taichi/program/program.h +++ b/taichi/program/program.h @@ -6,6 +6,7 @@ #include #include #include +#include #define TI_RUNTIME_HOST #include "taichi/aot/module_builder.h" @@ -125,9 +126,12 @@ class TI_DLL_EXPORT Program { CompileConfig &this_thread_config() { auto thread_id = std::this_thread::get_id(); + std::shared_lock sharedLock(compile_config_mut); if (!configs.count(thread_id)) { - std::lock_guard _(compile_config_mut); + sharedLock.unlock(); + std::unique_lock uniqueLock(compile_config_mut); configs[thread_id] = configs[main_thread_id_]; + return configs[thread_id]; } return configs[thread_id]; } @@ -397,7 +401,7 @@ class TI_DLL_EXPORT Program { std::vector> ndarrays_; std::vector> textures_; - std::mutex compile_config_mut; + std::shared_mutex compile_config_mut; }; } // namespace taichi::lang