Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 28 Jun 2022 20:13:36 +0000 (22:13 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Tue, 28 Jun 2022 20:13:49 +0000 (22:13 +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 3d9e995..d46d75a 100644 (file)
@@ -5,29 +5,28 @@
 
 pthread_mutex_t mutex;
 
-static void* thread_fun(void* ignore)
+static void* thread_fun(void* val)
 {
   pthread_mutex_lock(&mutex);
   pthread_mutex_unlock(&mutex);
 
+  fprintf(stderr, "The thread %d is terminating.\n", *(int*)val);
   return NULL;
 }
 
 int main(int argc, char* argv[])
 {
-  fprintf(stderr, "User main is starting\n");
-
   pthread_mutex_init(&mutex, NULL);
 
+  int id[2] = {0, 1};
   pthread_t thread1;
   pthread_t thread2;
-  pthread_create(&thread1, NULL, thread_fun, NULL);
-  fprintf(stderr, "here\n");
-  pthread_create(&thread2, NULL, thread_fun, NULL);
-  fprintf(stderr, "there\n");
+  pthread_create(&thread1, NULL, thread_fun, (void*)&id[0]);
+  pthread_create(&thread2, NULL, thread_fun, (void*)&id[1]);
+  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..b3bba4d
--- /dev/null
@@ -0,0 +1,7 @@
+$ ./pthread-mutex-simple
+> [0.000000] [sthread/INFO] Starting the simulation.
+> The thread 0 is terminating.
+> All threads are started.
+> The thread 1 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 8062a5c..d3e41ae 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 void* /*pthread_attr_t* attr
 {
   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())