Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
One more static initialization order fiasco.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 19 Jan 2021 08:14:48 +0000 (09:14 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 19 Jan 2021 08:40:31 +0000 (09:40 +0100)
src/mc/mc_base.cpp
src/mc/mc_config.cpp
src/mc/mc_config.hpp
src/mc/mc_replay.hpp
src/simix/smx_global.cpp

index 6b498b6..5cc8b49 100644 (file)
@@ -8,6 +8,7 @@
 #include "src/kernel/activity/CommImpl.hpp"
 #include "src/kernel/activity/MutexImpl.hpp"
 #include "src/mc/checker/SimcallInspector.hpp"
+#include "src/mc/mc_config.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/simix/smx_private.hpp"
 
@@ -170,7 +171,7 @@ bool request_is_visible(const s_smx_simcall* req)
 
 int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max)
 {
-  if (not MC_is_active() && MC_record_path.empty()) {
+  if (not MC_is_active() && not MC_record_replay_is_active()) {
     static simgrid::xbt::random::XbtRandom prng;
     return prng.uniform_int(min, max);
   }
index b66a228..cfe3511 100644 (file)
@@ -3,6 +3,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
+#include "src/mc/mc_config.hpp"
 #include "src/mc/mc_replay.hpp"
 #include <simgrid/sg_config.hpp>
 #if SIMGRID_HAVE_MC
@@ -32,11 +33,13 @@ static void _mc_cfg_cb_check(const char* spec, bool more_check = true)
 
 /* Replay (this part is enabled even if MC it disabled) */
 simgrid::config::Flag<std::string> _sg_mc_record_path{
-    "model-check/replay", "Model-check path to replay (as reported by SimGrid when a violation is reported)", ""};
+    "model-check/replay", "Model-check path to replay (as reported by SimGrid when a violation is reported)", "",
+    [](const std::string& value) { MC_record_path() = value; }};
 
 simgrid::config::Flag<bool> _sg_mc_timeout{
-    "model-check/timeout", "Whether to enable timeouts for wait requests", false,
-    [](bool) { _mc_cfg_cb_check("value to enable/disable timeout for wait requests", MC_record_path.empty()); }};
+    "model-check/timeout", "Whether to enable timeouts for wait requests", false, [](bool) {
+      _mc_cfg_cb_check("value to enable/disable timeout for wait requests", not MC_record_replay_is_active());
+    }};
 
 #if SIMGRID_HAVE_MC
 int _sg_do_model_check = 0;
index 93392ef..f249c75 100644 (file)
@@ -11,7 +11,6 @@
 /********************************** Configuration of MC **************************************/
 extern "C" XBT_PUBLIC int _sg_do_model_check;
 extern XBT_PUBLIC simgrid::config::Flag<std::string> _sg_mc_buffering;
-extern XBT_PUBLIC simgrid::config::Flag<std::string> _sg_mc_record_path;
 extern XBT_PRIVATE simgrid::config::Flag<int> _sg_mc_checkpoint;
 extern XBT_PUBLIC simgrid::config::Flag<std::string> _sg_mc_property_file;
 extern XBT_PUBLIC simgrid::config::Flag<bool> _sg_mc_comms_determinism;
index 5558e5a..4d09362 100644 (file)
@@ -6,18 +6,23 @@
 #ifndef SIMGRID_MC_REPLAY_H
 #define SIMGRID_MC_REPLAY_H
 
-#include "src/mc/mc_config.hpp"
+#include <string>
 
 /** Replay path (if any) in string representation
  *
  *  This is using the format generated by traceToString().
+ *  Use a function to avoid static initialization order fiasco.
  */
-#define MC_record_path (_sg_mc_record_path.get())
+inline std::string& MC_record_path()
+{
+  static std::string value;
+  return value;
+}
 
 /** Whether the replay mode is enabled */
 static inline int MC_record_replay_is_active()
 {
-  return not MC_record_path.empty();
+  return not MC_record_path().empty();
 }
 
 #endif
index c03d20b..d0e91ad 100644 (file)
@@ -412,7 +412,7 @@ static bool SIMIX_execute_timers()
 void SIMIX_run()
 {
   if (MC_record_replay_is_active()) {
-    simgrid::mc::replay(MC_record_path);
+    simgrid::mc::replay(MC_record_path());
     return;
   }