Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make sthread work out of MC build trees
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 26 Jun 2022 10:48:35 +0000 (12:48 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 26 Jun 2022 10:48:35 +0000 (12:48 +0200)
src/kernel/context/Context.cpp
src/kernel/context/ContextSwapped.cpp
src/sthread/sthread.h
src/xbt/xbt_main.cpp

index 66a895b..f25b980 100644 (file)
@@ -9,6 +9,7 @@
 #include "simgrid/s4u/Host.hpp"
 #include "src/kernel/activity/CommImpl.hpp"
 #include "src/kernel/context/Context.hpp"
+#include "src/sthread/sthread.h" // sthread_inside_simgrid
 #include "src/surf/surf_interface.hpp"
 
 #include <vector>
@@ -139,6 +140,7 @@ Context::~Context()
 void Context::stop()
 {
   this->actor_->cleanup_from_self();
+  sthread_inside_simgrid = 1;
   throw ForcefulKillException(); // clean RAII variables with the dedicated exception
 }
 AttachContext::~AttachContext() = default;
index 92e9c7f..eb4e41b 100644 (file)
@@ -249,6 +249,7 @@ void SwappedContext::resume()
     // Save my current soul (either maestro, or one of the minions) in a thread-specific area
     worker_context_ = old;
   }
+  sthread_inside_simgrid = 0;
   // Switch my soul and the actor's one
   Context::set_current(this);
   old->swap_into(this);
@@ -290,10 +291,12 @@ void SwappedContext::suspend()
     if (i < engine->get_actor_to_run_count()) {
       /* Actually swap into the next actor directly without transiting to maestro */
       XBT_DEBUG("Run next actor");
+      sthread_inside_simgrid = 0;
       next_context = static_cast<SwappedContext*>(engine->get_actor_to_run_at(i)->context_.get());
     } else {
       /* all processes were run, actually return to maestro */
       XBT_DEBUG("No more actors to run");
+      sthread_inside_simgrid = 1;
       next_context = factory_.maestro_context_;
     }
   }
index 6e7d4f8..233dbb1 100644 (file)
@@ -10,8 +10,7 @@
 #if defined(__cplusplus)
 extern "C" {
 #endif
-extern int
-    sthread_inside_simgrid; // allows logs and library constructors to disable the interception on pthread operations
+extern volatile int sthread_inside_simgrid; // Only intercept pthread calls in user code
 
 int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char**, char**));
 
index 194479b..6086dad 100644 (file)
@@ -41,7 +41,7 @@ std::string binary_name;          /* Name of the system process containing us (m
 std::vector<std::string> cmdline; /* all we got in argv */
 } // namespace simgrid::xbt
 
-int sthread_inside_simgrid = 1; // whether sthread should leave pthread operations or intercept them.
+volatile int sthread_inside_simgrid = 1; // Only intercept pthread calls in user code.
 
 int xbt_initialized = 0;
 simgrid::config::Flag<bool> cfg_dbg_clean_atexit{