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