Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-hitonami committed Nov 9, 2022
1 parent b5e661d commit c85e137
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions taichi/program/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <optional>
#include <atomic>
#include <stack>
#include <shared_mutex>

#define TI_RUNTIME_HOST
#include "taichi/aot/module_builder.h"
Expand Down Expand Up @@ -125,9 +126,12 @@ class TI_DLL_EXPORT Program {

CompileConfig &this_thread_config() {
auto thread_id = std::this_thread::get_id();
std::shared_lock<std::shared_mutex> sharedLock(compile_config_mut);
if (!configs.count(thread_id)) {
std::lock_guard<std::mutex> _(compile_config_mut);
sharedLock.unlock();
std::unique_lock<std::shared_mutex> uniqueLock(compile_config_mut);
configs[thread_id] = configs[main_thread_id_];
return configs[thread_id];
}
return configs[thread_id];
}
Expand Down Expand Up @@ -397,7 +401,7 @@ class TI_DLL_EXPORT Program {
std::vector<std::unique_ptr<Ndarray>> ndarrays_;
std::vector<std::unique_ptr<Texture>> textures_;

std::mutex compile_config_mut;
std::shared_mutex compile_config_mut;
};

} // namespace taichi::lang

0 comments on commit c85e137

Please sign in to comment.