examples/c/platform-properties/c-platform-properties
examples/c/plugin-host-load/c-plugin-host-load
examples/c/synchro-semaphore/c-synchro-semaphore
-examples/deprecated/msg/mc/bugged2_liveness
-examples/deprecated/msg/mc/centralized_mutex
examples/cpp/actor-create/s4u-actor-create
examples/cpp/actor-daemon/s4u-actor-daemon
examples/cpp/actor-exiting/s4u-actor-exiting
examples/cpp/mc-bugged1/s4u-mc-bugged1
examples/cpp/mc-bugged1-liveness/s4u-mc-bugged1-liveness
examples/cpp/mc-bugged2/s4u-mc-bugged2
+examples/cpp/mc-bugged2-liveness/s4u-mc-bugged2-liveness
+examples/cpp/mc-centralized-mutex/s4u-mc-centralized-mutex
examples/cpp/mc-electric-fence/s4u-mc-electric-fence
examples/cpp/mc-failing-assert/s4u-mc-failing-assert
examples/cpp/network-factors/s4u-network-factors
include examples/cpp/mc-bugged2-liveness/s4u-mc-bugged2-liveness.tesh
include examples/cpp/mc-bugged2/s4u-mc-bugged2.cpp
include examples/cpp/mc-bugged2/s4u-mc-bugged2.tesh
+include examples/cpp/mc-centralized-mutex/s4u-mc-centralized-mutex.cpp
+include examples/cpp/mc-centralized-mutex/s4u-mc-centralized-mutex.tesh
include examples/cpp/mc-electric-fence/s4u-mc-electric-fence.cpp
include examples/cpp/mc-electric-fence/s4u-mc-electric-fence.tesh
include examples/cpp/mc-failing-assert/s4u-mc-failing-assert.cpp
include examples/deprecated/java/trace/pingpong/Receiver.java
include examples/deprecated/java/trace/pingpong/Sender.java
include examples/deprecated/java/trace/pingpong/trace-pingpong.tesh
-include examples/deprecated/msg/mc/centralized_mutex.c
-include examples/deprecated/msg/mc/centralized_mutex.tesh
-include examples/deprecated/msg/mc/deploy_centralized_mutex.xml
include examples/python/actor-create/actor-create.py
include examples/python/actor-create/actor-create.tesh
include examples/python/actor-daemon/actor-daemon.py
include examples/c/CMakeLists.txt
include examples/cpp/CMakeLists.txt
include examples/deprecated/java/CMakeLists.txt
-include examples/deprecated/msg/mc/CMakeLists.txt
include examples/platforms/CMakeLists.txt
include examples/platforms/bypassRoute.xml
include examples/platforms/bypassZoneRoute.xml
- examples/cpp/ for examples using the S4U API
- examples/smpi/ or examples using the SMPI API
- examples/platforms/ only contains platforms descriptions in the XML format (see @ref platform for details)
- - examples/deprecated/msg/ for examples using the MSG API. Here the naming convention is package-example (e.g., app-masterworker).
- examples/deprecated/java/ for examples using the Java bindings to the MSG API. This directory contains packages (app, async,
cloud, ...) which in turn contain individual examples. If your new example fits in an existing package, add it here,
or create a new package otherwise.
endif()
else()
- foreach (example mc-bugged1 mc-bugged2 mc-failing-assert mc-electric-fence
+ foreach (example mc-bugged1 mc-bugged2 mc-centralized-mutex mc-failing-assert mc-electric-fence
mc-bugged1-liveness mc-bugged2-liveness)
set(_${example}_disable 1)
endforeach()
exec-async exec-basic exec-dvfs exec-remote exec-waitany exec-waitfor exec-dependent exec-unassigned
exec-ptask-multicore exec-cpu-nonlinear exec-cpu-factors exec-failure
maestro-set
- mc-bugged1 mc-bugged1-liveness mc-bugged2 mc-bugged2-liveness mc-electric-fence mc-failing-assert
+ mc-bugged1 mc-bugged1-liveness mc-bugged2 mc-bugged2-liveness mc-centralized-mutex mc-electric-fence mc-failing-assert
network-ns3 network-ns3-wifi network-wifi
io-async io-priority io-degradation io-file-system io-file-remote io-disk-raw io-dependent
platform-failures platform-profile platform-properties
static void coordinator()
{
- int CS_used = 0;
+ bool CS_used = false;
std::queue<simgrid::s4u::Mailbox*> requests;
simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator");
if (m->return_mailbox->get_name() != "1") {
XBT_INFO("CS idle. Grant immediately");
m->return_mailbox->put(new Message(Message::Kind::GRANT, mbox), 1000);
- CS_used = 1;
+ CS_used = true;
}
}
} else {
req->put(new Message(Message::Kind::GRANT, mbox), 1000);
} else {
requests.push(req);
- CS_used = 0;
+ CS_used = false;
}
} else {
XBT_INFO("CS release. resource now idle");
- CS_used = 0;
+ CS_used = false;
}
}
}
class Message {
public:
- enum class Kind { GRANT, NOT_GRANT, REQUEST, RELEASE };
+ enum class Kind { GRANT, NOT_GRANT, REQUEST };
Kind kind = Kind::GRANT;
simgrid::s4u::Mailbox* return_mailbox = nullptr;
explicit Message(Message::Kind kind, simgrid::s4u::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {}
static void coordinator()
{
- int CS_used = 0; // initially the CS is idle
+ bool CS_used = false; // initially the CS is idle
std::queue<simgrid::s4u::Mailbox*> requests;
simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator");
} else { // can serve it immediately
XBT_INFO("CS idle. Grant immediately");
m->return_mailbox->put(new Message(Message::Kind::GRANT, mbox), 1000);
- CS_used = 1;
+ CS_used = true;
}
} else { // that's a release. Check if someone was waiting for the lock
XBT_INFO("CS release. resource now idle");
- CS_used = 0;
+ CS_used = false;
}
}
}
--- /dev/null
+/* Copyright (c) 2010-2021. 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. */
+
+/***************** Centralized Mutual Exclusion Algorithm *********************/
+/* This example implements a centralized mutual exclusion algorithm. */
+/* There is no bug on it, it is just provided to test the state space */
+/* reduction of DPOR. */
+/******************************************************************************/
+
+#include "simgrid/s4u.hpp"
+
+#define AMOUNT_OF_CLIENTS 4
+#define CS_PER_PROCESS 2
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(centralized, "my log messages");
+
+class Message {
+public:
+ enum class Kind { GRANT, REQUEST, RELEASE };
+ Kind kind = Kind::GRANT;
+ simgrid::s4u::Mailbox* return_mailbox = nullptr;
+ explicit Message(Message::Kind kind, simgrid::s4u::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {}
+};
+
+static void coordinator()
+{
+ std::queue<simgrid::s4u::Mailbox*> requests;
+ simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator");
+
+ bool CS_used = false; // initially the CS is idle
+ int todo = AMOUNT_OF_CLIENTS * CS_PER_PROCESS; // amount of releases we are expecting
+
+ while (todo > 0) {
+ auto m = mbox->get_unique<Message>();
+ if (m->kind == Message::Kind::REQUEST) {
+ if (CS_used) { // need to push the request in the vector
+ XBT_INFO("CS already used. Queue the request");
+ requests.push(m->return_mailbox);
+ } else { // can serve it immediately
+ XBT_INFO("CS idle. Grant immediately");
+ m->return_mailbox->put(new Message(Message::Kind::GRANT, mbox), 1000);
+ CS_used = true;
+ }
+ } else { // that's a release. Check if someone was waiting for the lock
+ if (not requests.empty()) {
+ XBT_INFO("CS release. Grant to queued requests (queue size: %zu)", requests.size());
+ simgrid::s4u::Mailbox* req = requests.front();
+ requests.pop();
+ req->put(new Message(Message::Kind::GRANT, mbox), 1000);
+ todo--;
+ } else { // nobody wants it
+ XBT_INFO("CS release. resource now idle");
+ CS_used = false;
+ todo--;
+ }
+ }
+ }
+ XBT_INFO("Received all releases, quit now");
+}
+
+static void client()
+{
+ aid_t my_pid = simgrid::s4u::this_actor::get_pid();
+
+ simgrid::s4u::Mailbox* my_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(my_pid));
+
+ // request the CS 3 times, sleeping a bit in between
+ for (int i = 0; i < CS_PER_PROCESS; i++) {
+ XBT_INFO("Ask the request");
+ simgrid::s4u::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::REQUEST, my_mailbox), 1000);
+ // wait for the answer
+ auto grant = my_mailbox->get_unique<Message>();
+ XBT_INFO("got the answer. Sleep a bit and release it");
+ simgrid::s4u::this_actor::sleep_for(1);
+
+ simgrid::s4u::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::RELEASE, my_mailbox), 1000);
+ simgrid::s4u::this_actor::sleep_for(my_pid);
+ }
+ XBT_INFO("Got all the CS I wanted, quit now");
+}
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine e(&argc, argv);
+
+ e.load_platform(argv[1]);
+
+ simgrid::s4u::Actor::create("coordinator", e.host_by_name("Tremblay"), coordinator);
+ simgrid::s4u::Actor::create("client", e.host_by_name("Fafard"), client);
+ simgrid::s4u::Actor::create("client", e.host_by_name("Boivin"), client);
+ simgrid::s4u::Actor::create("client", e.host_by_name("Jacquelin"), client);
+ simgrid::s4u::Actor::create("client", e.host_by_name("Ginette"), client);
+
+ e.run();
+
+ return 0;
+}
--- /dev/null
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/s4u-mc-centralized-mutex ${platfdir:=.}/small_platform.xml "--log=root.fmt:[%5.2r]%e[%11P][%9h]%e%m%n"
+> [ 0.00] [ client][ Fafard] Ask the request
+> [ 0.00] [ client][ Boivin] Ask the request
+> [ 0.00] [ client][Jacquelin] Ask the request
+> [ 0.00] [ client][ Ginette] Ask the request
+> [ 0.03] [coordinator][ Tremblay] CS idle. Grant immediately
+> [ 0.05] [ client][ Fafard] got the answer. Sleep a bit and release it
+> [ 0.25] [coordinator][ Tremblay] CS already used. Queue the request
+> [ 1.12] [coordinator][ Tremblay] CS already used. Queue the request
+> [ 1.13] [coordinator][ Tremblay] CS already used. Queue the request
+> [ 1.16] [coordinator][ Tremblay] CS release. Grant to queued requests (queue size: 3)
+> [ 1.36] [ client][ Boivin] got the answer. Sleep a bit and release it
+> [ 2.56] [coordinator][ Tremblay] CS release. Grant to queued requests (queue size: 2)
+> [ 3.16] [ client][ Fafard] Ask the request
+> [ 3.42] [ client][Jacquelin] got the answer. Sleep a bit and release it
+> [ 3.45] [coordinator][ Tremblay] CS already used. Queue the request
+> [ 5.28] [coordinator][ Tremblay] CS release. Grant to queued requests (queue size: 2)
+> [ 5.30] [ client][ Ginette] got the answer. Sleep a bit and release it
+> [ 5.56] [ client][ Boivin] Ask the request
+> [ 5.77] [coordinator][ Tremblay] CS already used. Queue the request
+> [ 6.32] [coordinator][ Tremblay] CS release. Grant to queued requests (queue size: 2)
+> [ 6.34] [ client][ Fafard] got the answer. Sleep a bit and release it
+> [ 7.37] [coordinator][ Tremblay] CS release. Grant to queued requests (queue size: 1)
+> [ 7.57] [ client][ Boivin] got the answer. Sleep a bit and release it
+> [ 8.78] [coordinator][ Tremblay] CS release. resource now idle
+> [ 9.28] [ client][Jacquelin] Ask the request
+> [ 9.37] [ client][ Fafard] Got all the CS I wanted, quit now
+> [10.15] [coordinator][ Tremblay] CS idle. Grant immediately
+> [11.01] [ client][Jacquelin] got the answer. Sleep a bit and release it
+> [11.32] [ client][ Ginette] Ask the request
+> [11.33] [coordinator][ Tremblay] CS already used. Queue the request
+> [11.78] [ client][ Boivin] Got all the CS I wanted, quit now
+> [12.87] [coordinator][ Tremblay] CS release. Grant to queued requests (queue size: 1)
+> [12.88] [ client][ Ginette] got the answer. Sleep a bit and release it
+> [13.90] [coordinator][ Tremblay] CS release. resource now idle
+> [13.90] [coordinator][ Tremblay] Received all releases, quit now
+> [16.87] [ client][Jacquelin] Got all the CS I wanted, quit now
+> [18.90] [ client][ Ginette] Got all the CS I wanted, quit now
+++ /dev/null
-foreach (x centralized_mutex)
- if(SIMGRID_HAVE_MC AND SIMGRID_HAVE_MSG)
- add_executable (${x} EXCLUDE_FROM_ALL ${x}.c)
- target_link_libraries(${x} simgrid)
- add_dependencies(tests ${x})
- endif()
- set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}.c)
- set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/deploy_${x}.xml)
-endforeach()
-
-set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/centralized_mutex.tesh PARENT_SCOPE)
-set(xml_files ${xml_files} PARENT_SCOPE)
-set(examples_src ${examples_src} PARENT_SCOPE)
+++ /dev/null
-/* Copyright (c) 2010-2021. 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. */
-
-/***************** Centralized Mutual Exclusion Algorithm *********************/
-/* This example implements a centralized mutual exclusion algorithm. */
-/* There is no bug on it, it is just provided to test the state space */
-/* reduction of DPOR. */
-/******************************************************************************/
-
-#include "simgrid/msg.h"
-
-#define AMOUNT_OF_CLIENTS 4
-#define CS_PER_PROCESS 2
-XBT_LOG_NEW_DEFAULT_CATEGORY(centralized, "my log messages");
-
-static int coordinator(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
-{
- xbt_dynar_t requests = xbt_dynar_new(sizeof(char *), NULL); // dynamic vector storing requests (which are char*)
- int CS_used = 0; // initially the CS is idle
- int todo = AMOUNT_OF_CLIENTS * CS_PER_PROCESS; // amount of releases we are expecting
- while (todo > 0) {
- msg_task_t task = NULL;
- MSG_task_receive(&task, "coordinator");
- const char *kind = MSG_task_get_name(task); //is it a request or a release?
- if (!strcmp(kind, "request")) { // that's a request
- char *req = MSG_task_get_data(task);
- if (CS_used) { // need to push the request in the vector
- XBT_INFO("CS already used. Queue the request");
- xbt_dynar_push(requests, &req);
- } else { // can serve it immediately
- XBT_INFO("CS idle. Grant immediately");
- msg_task_t answer = MSG_task_create("grant", 0, 1000, NULL);
- MSG_task_send(answer, req);
- CS_used = 1;
- }
- } else { // that's a release. Check if someone was waiting for the lock
- if (!xbt_dynar_is_empty(requests)) {
- XBT_INFO("CS release. Grant to queued requests (queue size: %lu)", xbt_dynar_length(requests));
- char *req;
- xbt_dynar_shift(requests, &req);
- MSG_task_send(MSG_task_create("grant", 0, 1000, NULL), req);
- todo--;
- } else { // nobody wants it
- XBT_INFO("CS release. resource now idle");
- CS_used = 0;
- todo--;
- }
- }
- MSG_task_destroy(task);
- }
- XBT_INFO("Received all releases, quit now");
- return 0;
-}
-
-static int client(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
-{
- int my_pid = MSG_process_get_PID(MSG_process_self());
- // use my pid as name of mailbox to contact me
- char *my_mailbox = bprintf("%d", my_pid);
- // request the CS 3 times, sleeping a bit in between
- int i;
- for (i = 0; i < CS_PER_PROCESS; i++) {
- XBT_INFO("Ask the request");
- MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
- // wait the answer
- msg_task_t grant = NULL;
- MSG_task_receive(&grant, my_mailbox);
- MSG_task_destroy(grant);
- XBT_INFO("got the answer. Sleep a bit and release it");
- MSG_process_sleep(1);
- MSG_task_send(MSG_task_create("release", 0, 1000, NULL), "coordinator");
- MSG_process_sleep(my_pid);
- }
- XBT_INFO("Got all the CS I wanted, quit now");
- return 0;
-}
-
-int main(int argc, char *argv[])
-{
- MSG_init(&argc, argv);
- MSG_create_environment(argv[1]);
- MSG_function_register("coordinator", coordinator);
- MSG_function_register("client", client);
- MSG_launch_application("deploy_centralized_mutex.xml");
- MSG_main();
- return 0;
-}
+++ /dev/null
-#!/usr/bin/env tesh
-
-$ ${bindir:=.}/centralized_mutex ${platfdir:=.}/small_platform.xml
+++ /dev/null
-<?xml version='1.0'?>
-<!DOCTYPE platform SYSTEM "https://simgrid.org/simgrid.dtd">
-<platform version="4.1">
- <actor host="Tremblay" function="coordinator" />
-
- <actor host="Fafard" function="client" />
- <actor host="Boivin" function="client" />
- <actor host="Jacquelin" function="client" />
- <actor host="Ginette" function="client" />
-</platform>
examples/smpi/replay_multiple_manual_deploy/CMakeLists.txt
examples/python/CMakeLists.txt
examples/deprecated/java/CMakeLists.txt
- examples/deprecated/msg/mc/CMakeLists.txt
teshsuite/java/CMakeLists.txt
teshsuite/kernel/CMakeLists.txt