From: Arnaud Giersch Date: Tue, 11 Oct 2022 13:06:29 +0000 (+0200) Subject: Enable simple sthread example. X-Git-Tag: v3.34~782 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4a51df13a5942cd7cc33d2f1bcce308040945be2?ds=sidebyside Enable simple sthread example. --- diff --git a/MANIFEST.in b/MANIFEST.in index 65352d5e67..a6870b680b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/examples/sthread/CMakeLists.txt b/examples/sthread/CMakeLists.txt index 81d4ef1dea..79857df41c 100644 --- a/examples/sthread/CMakeLists.txt +++ b/examples/sthread/CMakeLists.txt @@ -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() diff --git a/examples/sthread/sthread-mutex-simple.c b/examples/sthread/sthread-mutex-simple.c index c0f48f68c5..76fa009c94 100644 --- a/examples/sthread/sthread-mutex-simple.c +++ b/examples/sthread/sthread-mutex-simple.c @@ -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 index 0000000000..ffa04c1dc4 --- /dev/null +++ b/examples/sthread/sthread-mutex-simple.tesh @@ -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.