Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix an initialization race around the AppSide
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 1 Apr 2023 09:45:54 +0000 (11:45 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sat, 1 Apr 2023 09:45:54 +0000 (11:45 +0200)
src/kernel/EngineImpl.cpp
src/mc/remote/AppSide.cpp
src/mc/remote/AppSide.hpp

index 5a6dd12..a5b2d57 100644 (file)
@@ -175,7 +175,7 @@ void EngineImpl::initialize(int* argc, char** argv)
   // The communication initialization is done ASAP, as we need to get some init parameters from the MC for different
   // layers. But instance_ needs to be created, as we send the address of some of its fields to the MC that wants to
   // read them directly.
-  simgrid::mc::AppSide::initialize();
+  simgrid::mc::AppSide::get(); // To ensure that it's initialized
 #endif
 
   if (static bool inited = false; not inited) {
index f6b53c9..992df22 100644 (file)
@@ -40,15 +40,15 @@ namespace simgrid::mc {
 
 std::unique_ptr<AppSide> AppSide::instance_;
 
-AppSide* AppSide::initialize()
+AppSide* AppSide::get()
 {
-  if (not std::getenv(MC_ENV_SOCKET_FD)) // We are not in MC mode: don't initialize the MC world
-    return nullptr;
-
-  // Do not break if we are called multiple times:
+  // Only initialize the MC world once
   if (instance_)
     return instance_.get();
 
+  if (not std::getenv(MC_ENV_SOCKET_FD)) // We are not in MC mode: don't initialize the MC world
+    return nullptr;
+
   simgrid::mc::model_checking_mode = ModelCheckingMode::APP_SIDE;
 
   setvbuf(stdout, nullptr, _IOLBF, 0);
index 5dcb934..fba78bc 100644 (file)
@@ -52,10 +52,8 @@ public:
   void declare_stack(void* stack, size_t size, ucontext_t* context) const;
 #endif
 
-  // Singleton :/
   // TODO, remove the singleton antipattern.
-  static AppSide* initialize();
-  static AppSide* get() { return instance_.get(); }
+  static AppSide* get();
 };
 } // namespace simgrid::mc