add h5parm singleton
3 unresolved threads
3 unresolved threads
libhdf5 is not always thread safe, and it is not necessary to re-read the same h5 file when multiple threads are accessing it, this fixes both issues by using a singleton for the h5 file, the h5parm is passed as a reference to all threads (so h5parm is assumed thread safe, for reading)
Edited by Sarod Yatawatta
Merge request reports
Activity
Filter activity
assigned to @yatawatta
added 3 commits
-
8f7d7227...791b90f3 - 2 commits from branch
master
- fe2606d5 - add h5parm singleton
-
8f7d7227...791b90f3 - 2 commits from branch
requested review from @dijkema
mentioned in commit 24c71a31
130 130 #endif /* HAVE_LIBDIRAC || HAVE_LIBDIRAC_CUDA */ 131 131 132 // Singleton to open and read H5 file only by one thread 133 // But H5Parm itself is assumed thread-safe 134 class H5ParmSingle { 135 private: 136 explicit H5ParmSingle() : is_opened_(false) {} 137 std::mutex mutex_; 138 bool is_opened_; 139 140 public: 141 H5ParmSingle(H5ParmSingle const&) = delete; 142 H5ParmSingle& operator=(H5ParmSingle const&) = delete; 143 ~H5ParmSingle(){}; 144 145 static H5ParmSingle* get_instance() { 135 private: 136 explicit H5ParmSingle() : is_opened_(false) {} 137 std::mutex mutex_; 138 bool is_opened_; 139 140 public: 141 H5ParmSingle(H5ParmSingle const&) = delete; 142 H5ParmSingle& operator=(H5ParmSingle const&) = delete; 143 ~H5ParmSingle(){}; 144 145 static H5ParmSingle* get_instance() { 146 static H5ParmSingle instance; 147 return &instance; 148 } 149 150 schaapcommon::h5parm::H5Parm& open_file(const std::string& h5_name); 129 129 }; 130 130 #endif /* HAVE_LIBDIRAC || HAVE_LIBDIRAC_CUDA */ 131 131 132 // Singleton to open and read H5 file only by one thread 133 // But H5Parm itself is assumed thread-safe 134 class H5ParmSingle { 135 private: 136 explicit H5ParmSingle() : is_opened_(false) {} 137 std::mutex mutex_; 138 bool is_opened_; These should be in the bottom of the class.
You can also use
bool is_opened_ = false
and remove all constructors and the destructor, and put theH5ParmSingle()
constructor as= default
.Edited by Andre Offringa
mentioned in issue rapthor#21
Please register or sign in to reply