]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use std::call_once() instead of hand-rolling a solution. 13762/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 May 2022 01:52:22 +0000 (19:52 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Fri, 20 May 2022 01:52:22 +0000 (19:52 -0600)
source/base/multithread_info.cc

index f9d6c984d2ff0179bbdf438bf7c7e23926a016fa..1112b88efe849021453098b7bd666e8396179291 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <algorithm>
 #include <cstdlib> // for std::getenv
+#include <mutex>
 #include <thread>
 
 #ifdef DEAL_II_WITH_TBB
@@ -144,14 +145,14 @@ MultithreadInfo::memory_consumption()
 void
 MultithreadInfo::initialize_multithreading()
 {
-  static bool done = false;
-  if (done)
-    return;
-
-  MultithreadInfo::set_thread_limit(numbers::invalid_unsigned_int);
-  done = true;
+  static std::once_flag is_initialized;
+  std::call_once(is_initialized, []() {
+    MultithreadInfo::set_thread_limit(numbers::invalid_unsigned_int);
+  });
 }
 
+
+
 #ifdef DEAL_II_WITH_TASKFLOW
 tf::Executor &
 MultithreadInfo::get_taskflow_executor()

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.