From: Fred Suter Date: Fri, 27 Oct 2023 12:34:54 +0000 (-0400) Subject: Merge branch 'master' into mq X-Git-Tag: v3.35~89^2~28^2 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/498f97c6a9dba4c63ba605da7c7df669bffa96bf?hp=eb680c004b00a59218e7cdaa77fc2c96066c3548 Merge branch 'master' into mq --- diff --git a/ChangeLog b/ChangeLog index 893664d9bc..605242b95a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,11 +8,16 @@ S4U: on symmetric routes. - Introduce a Mailbox::get_async() with no payload parameter. You can use the new Comm::get_payload() once the communication is over to retrieve the payload. + - Implement recursive mutexes. Simply pass true to the constructor to get one. SMPI: - New SMPI_app_instance_join(): wait for the completion of a started MPI instance - MPI_UNIVERSE_SIZE now initialized to the total amount of hosts in the platform +sthread: + - Implement recursive pthreads. + - Many bug fixes. + Python: - Make the host_load plugin available from Python. See examples/python/plugin-host-load - Mailbox::get_async() does not return a pair anymore. Use comm.get_payload() instead. diff --git a/MANIFEST.in b/MANIFEST.in index 2a24cda650..f2f6e1d086 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -645,9 +645,12 @@ include examples/smpi/trace_call_location/trace_call_location.c include examples/smpi/trace_call_location/trace_call_location.tesh include examples/smpi/trace_simple/trace_simple.c include examples/smpi/trace_simple/trace_simple.tesh +include examples/sthread/pthread-mc-mutex-recursive.tesh include examples/sthread/pthread-mc-mutex-simple.tesh include examples/sthread/pthread-mc-mutex-simpledeadlock.tesh include examples/sthread/pthread-mc-producer-consumer.tesh +include examples/sthread/pthread-mutex-recursive.c +include examples/sthread/pthread-mutex-recursive.tesh include examples/sthread/pthread-mutex-simple.c include examples/sthread/pthread-mutex-simple.tesh include examples/sthread/pthread-mutex-simpledeadlock.c diff --git a/examples/sthread/pthread-mutex-recursive.c b/examples/sthread/pthread-mutex-recursive.c new file mode 100644 index 0000000000..482cf3ee7f --- /dev/null +++ b/examples/sthread/pthread-mutex-recursive.c @@ -0,0 +1,65 @@ +/* Copyright (c) 2002-2023. The SimGrid Team. All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +/* Code with both recursive and non-recursive mutexes */ + +#include +#include +#include + +// Structure to hold the mutex's name and pointer to the actual mutex +typedef struct { + const char* name; + pthread_mutex_t* mutex; +} ThreadData; + +static void* thread_function(void* arg) +{ + ThreadData* data = (ThreadData*)arg; + pthread_mutex_t* mutex = data->mutex; + const char* name = data->name; + + pthread_mutex_lock(mutex); + fprintf(stderr, "Got the lock on the %s mutex.\n", name); + + // Attempt to relock the mutex - This behavior depends on the mutex type + if (pthread_mutex_trylock(mutex) == 0) { + fprintf(stderr, "Got the lock again on the %s mutex.\n", name); + pthread_mutex_unlock(mutex); + } else { + fprintf(stderr, "Failed to relock the %s mutex.\n", name); + } + + pthread_mutex_unlock(mutex); + + // pthread_exit(NULL); TODO: segfaulting + return NULL; +} + +int main() +{ + pthread_t thread1, thread2; + pthread_mutex_t mutex_dflt = PTHREAD_MUTEX_INITIALIZER; // Non-recursive mutex + + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_t mutex_rec; + pthread_mutex_init(&mutex_rec, &attr); + + ThreadData data1 = {"default", &mutex_dflt}; + ThreadData data2 = {"recursive", &mutex_rec}; + + pthread_create(&thread1, NULL, thread_function, &data1); + pthread_create(&thread2, NULL, thread_function, &data2); + + pthread_join(thread1, NULL); + pthread_join(thread2, NULL); + + pthread_mutex_destroy(&mutex_dflt); + pthread_mutex_destroy(&mutex_rec); + + return 0; +} diff --git a/tools/cmake/Distrib.cmake b/tools/cmake/Distrib.cmake index 6a144b1ddf..50952960ff 100644 --- a/tools/cmake/Distrib.cmake +++ b/tools/cmake/Distrib.cmake @@ -43,7 +43,9 @@ add_custom_target(simgrid_convert_TI_traces ALL # libraries install(TARGETS simgrid DESTINATION ${CMAKE_INSTALL_LIBDIR}/) -install(TARGETS sthread DESTINATION ${CMAKE_INSTALL_LIBDIR}/) +if("${CMAKE_SYSTEM}" MATCHES "Linux") + install(TARGETS sthread DESTINATION ${CMAKE_INSTALL_LIBDIR}/) +endif() # pkg-config files configure_file("${CMAKE_HOME_DIRECTORY}/tools/pkg-config/simgrid.pc.in"