Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enable simple sthread example.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 11 Oct 2022 13:06:29 +0000 (15:06 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 11 Oct 2022 13:15:57 +0000 (15:15 +0200)
MANIFEST.in
examples/sthread/CMakeLists.txt
examples/sthread/sthread-mutex-simple.c
examples/sthread/sthread-mutex-simple.tesh [new file with mode: 0644]

index 65352d5..a6870b6 100644 (file)
@@ -717,6 +717,7 @@ include examples/smpi/trace_simple/trace_simple.tesh
 include examples/sthread/pthread-mutex-simple.c
 include examples/sthread/pthread-mutex-simple.tesh
 include examples/sthread/sthread-mutex-simple.c
+include examples/sthread/sthread-mutex-simple.tesh
 include src/include/catch_simgrid.hpp
 include teshsuite/java/semaphoregc/SemaphoreGC.java
 include teshsuite/java/semaphoregc/semaphoregc.tesh
index 81d4ef1..79857df 100644 (file)
@@ -32,10 +32,12 @@ foreach(x
     set_target_properties(sthread-${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
     target_link_libraries(sthread-${x} sthread)
     set_property(TARGET sthread-${x} APPEND PROPERTY INCLUDE_DIRECTORIES "${INTERNAL_INCLUDES}")
+
     add_dependencies(tests sthread-${x})
+    ADD_TESH_FACTORIES(sthread-${x} "^thread" --cd ${CMAKE_BINARY_DIR}/examples/sthread ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.tesh)
   endif()
 
-#  set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.tesh)
+  set(tesh_files    ${tesh_files}    ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.tesh)
   set(examples_src  ${examples_src}  ${CMAKE_CURRENT_SOURCE_DIR}/sthread-${x}.c)
 endforeach()
 
index c0f48f6..76fa009 100644 (file)
@@ -5,11 +5,12 @@
 
 sthread_mutex_t mutex;
 
-static void* thread_fun(void* ignore)
+static void* thread_fun(void* val)
 {
   sthread_mutex_lock(&mutex);
   sthread_mutex_unlock(&mutex);
 
+  fprintf(stderr, "The thread %d is terminating.\n", *(int*)val);
   return NULL;
 }
 
@@ -17,15 +18,17 @@ int main(int argc, char* argv[])
 {
   sthread_mutex_init(&mutex, NULL);
 
+  int id[2] = {0, 1};
   sthread_t thread1;
   sthread_t thread2;
-  sthread_create(&thread1, NULL, thread_fun, NULL);
-  sthread_create(&thread2, NULL, thread_fun, NULL);
+  sthread_create(&thread1, NULL, thread_fun, (void*)&id[0]);
+  sthread_create(&thread2, NULL, thread_fun, (void*)&id[1]);
+  fprintf(stderr, "All threads are started.\n");
   sthread_join(thread1, NULL);
   sthread_join(thread2, NULL);
 
   sthread_mutex_destroy(&mutex);
 
-  fprintf(stderr, "done\n");
+  fprintf(stderr, "User's main is terminating.\n");
   return 0;
 }
diff --git a/examples/sthread/sthread-mutex-simple.tesh b/examples/sthread/sthread-mutex-simple.tesh
new file mode 100644 (file)
index 0000000..ffa04c1
--- /dev/null
@@ -0,0 +1,7 @@
+$ ./sthread-mutex-simple
+> [0.000000] [sthread/INFO] Starting the simulation.
+> All threads are started.
+> The thread 0 is terminating.
+> The thread 1 is terminating.
+> User's main is terminating.
+> [0.000000] [sthread/INFO] All threads exited. Terminating the simulation.