Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add a TESH for the new sthread feature
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 28 Jun 2022 20:07:02 +0000 (22:07 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 28 Jun 2022 20:07:02 +0000 (22:07 +0200)
examples/sthread/CMakeLists.txt
examples/sthread/pthread-mutex-simple.c
examples/sthread/pthread-mutex-simple.tesh [new file with mode: 0644]
src/sthread/sthread.c
src/sthread/sthread_impl.cpp

index d547302..784b55a 100644 (file)
@@ -13,10 +13,12 @@ foreach(x
     target_link_libraries(pthread-${x} PRIVATE Threads::Threads)
 
     add_dependencies(tests pthread-${x})
+    ADD_TESH_FACTORIES(pthread-${x} "^thread" --setenv LD_PRELOAD=${CMAKE_BINARY_DIR}/lib/libsthread.so --cd ${CMAKE_BINARY_DIR}/examples/sthread ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh)
   endif()
 
-#  set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh)
+  set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.tesh)
   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/pthread-${x}.c)
+
 endforeach()
 
 # Regular sthread examples: test the internal interface for debugging purpose
index abe582d..b59214f 100644 (file)
@@ -10,6 +10,7 @@ static void* thread1_fun(void* ignore)
   pthread_mutex_lock(&mutex);
   pthread_mutex_unlock(&mutex);
 
+  fprintf(stderr, "The first thread is terminating.\n");
   return NULL;
 }
 static void* thread2_fun(void* ignore)
@@ -17,23 +18,21 @@ static void* thread2_fun(void* ignore)
   pthread_mutex_lock(&mutex);
   pthread_mutex_unlock(&mutex);
 
+  fprintf(stderr, "The second thread is terminating.\n");
   return NULL;
 }
 
 int main(int argc, char* argv[])
 {
-  fprintf(stderr, "User main is starting\n");
-
   pthread_mutex_init(&mutex, NULL);
 
   pthread_t thread1, thread2;
   pthread_create(&thread1, NULL, thread1_fun, NULL);
-  fprintf(stderr, "here\n");
   pthread_create(&thread2, NULL, thread2_fun, NULL);
-  fprintf(stderr, "there\n");
+  fprintf(stderr, "All threads are started.\n");
   pthread_join(thread1, NULL);
   pthread_join(thread2, NULL);
 
-  fprintf(stderr, "User main is done\n");
+  fprintf(stderr, "User's main is terminating.\n");
   return 0;
 }
diff --git a/examples/sthread/pthread-mutex-simple.tesh b/examples/sthread/pthread-mutex-simple.tesh
new file mode 100644 (file)
index 0000000..00827cb
--- /dev/null
@@ -0,0 +1,7 @@
+$ ./pthread-mutex-simple
+> [0.000000] [sthread/INFO] Starting the simulation.
+> The first thread is terminating.
+> All threads are started.
+> The second thread is terminating.
+> User's main is terminating.
+> [0.000000] [sthread/INFO] All threads exited. Terminating the simulation.
\ No newline at end of file
index dd9a67c..666cb36 100644 (file)
@@ -211,7 +211,6 @@ int __libc_start_main(int (*main)(int, char**, char**), int argc, char** argv, i
 
   /* Find the real __libc_start_main()... */
   typeof(&__libc_start_main) orig = dlsym(RTLD_NEXT, "__libc_start_main");
-  fprintf(stderr, "__libc_start_main\n");
   /* ... and call it with our custom main function */
   return orig(main_hook, argc, argv, init, fini, rtld_fini, stack_end);
 }
index 19a19b8..1780543 100644 (file)
@@ -30,7 +30,7 @@ int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char**
   std::ostringstream id;
   id << std::this_thread::get_id();
 
-  XBT_INFO("sthread main() is starting in thread %s", id.str().c_str());
+  XBT_DEBUG("sthread main() is starting in thread %s", id.str().c_str());
 
   sg4::Engine e(&argc, argv);
   auto* zone = sg4::create_full_zone("world");
@@ -41,8 +41,9 @@ int sthread_main(int argc, char** argv, char** envp, int (*raw_main)(int, char**
   sthread_enable();
   sg4::ActorPtr main_actor = sg4::Actor::create("tid 0", lilibeth, raw_main, argc, argv, envp);
 
-  XBT_INFO("sthread main() is launching the simulation");
+  XBT_INFO("Starting the simulation.");
   sg4::Engine::get_instance()->run();
+  XBT_INFO("All threads exited. Terminating the simulation.");
 
   return 0;
 }
@@ -67,7 +68,7 @@ int sthread_create(unsigned long int* thread, const /*pthread_attr_t*/ void* att
 {
   static int TID = 0;
   TID++;
-  XBT_INFO("Create thread %d", TID);
+  XBT_VERB("Create thread %d", TID);
   int rank = 0;
 #if HAVE_SMPI
   if (SMPI_is_inited())