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.
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
--- /dev/null
+/* 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 <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+// 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;
+}