From e5e983df594b8109f5ee69115692f3c0e3bee646 Mon Sep 17 00:00:00 2001 From: EricMEsch Date: Tue, 3 Sep 2024 14:19:21 +0200 Subject: [PATCH] Make reader thread-local to ensure thread-safety --- include/RMGGrabmayrGCReader.hh | 4 ++-- src/RMGGrabmayrGCReader.cc | 2 +- src/RMGUserAction.cc | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/RMGGrabmayrGCReader.hh b/include/RMGGrabmayrGCReader.hh index 153b162..0680561 100644 --- a/include/RMGGrabmayrGCReader.hh +++ b/include/RMGGrabmayrGCReader.hh @@ -38,7 +38,7 @@ struct GammaCascadeLine { class RMGGrabmayrGCReader { public: - static RMGGrabmayrGCReader* GetInstance(); + static G4ThreadLocal RMGGrabmayrGCReader* GetInstance(); ~RMGGrabmayrGCReader(); // RMGGrabmayrGCReader& operator=(const RMGGrabmayrGCReader&) = delete; @@ -49,7 +49,7 @@ class RMGGrabmayrGCReader { private: - static RMGGrabmayrGCReader* instance; + static G4ThreadLocal RMGGrabmayrGCReader* instance; RMGGrabmayrGCReader(); // std::vector> files; // map holding the corresponding file for each isotope diff --git a/src/RMGGrabmayrGCReader.cc b/src/RMGGrabmayrGCReader.cc index 8d50782..44b0e45 100644 --- a/src/RMGGrabmayrGCReader.cc +++ b/src/RMGGrabmayrGCReader.cc @@ -6,7 +6,7 @@ #include "RMGLog.hh" -RMGGrabmayrGCReader* RMGGrabmayrGCReader::instance = nullptr; +G4ThreadLocal RMGGrabmayrGCReader* RMGGrabmayrGCReader::instance = nullptr; RMGGrabmayrGCReader* RMGGrabmayrGCReader::GetInstance() { if (instance == nullptr) { instance = new RMGGrabmayrGCReader(); } diff --git a/src/RMGUserAction.cc b/src/RMGUserAction.cc index bfcea1c..4a5013d 100644 --- a/src/RMGUserAction.cc +++ b/src/RMGUserAction.cc @@ -72,7 +72,6 @@ void RMGUserAction::Build() const { this->SetUserAction(new RMGStackingAction(run_action)); this->SetUserAction(stepping_action); this->SetUserAction(tracking_action); - // Maybe add a check for multithreaded and only do this if not? RMGGrabmayrGCReader::GetInstance(); }