include examples/cpp/activityset-testany/s4u-activityset-testany.tesh
include examples/cpp/activityset-waitall/s4u-activityset-waitall.cpp
include examples/cpp/activityset-waitall/s4u-activityset-waitall.tesh
+include examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.cpp
+include examples/cpp/activityset-waitallfor/s4u-activityset-waitallfor.tesh
include examples/cpp/activityset-waitany/s4u-activityset-waitany.cpp
include examples/cpp/activityset-waitany/s4u-activityset-waitany.tesh
include examples/cpp/actor-create/s4u-actor-create.cpp
# Deal with each example
-foreach (example activityset-testany activityset-waitany activityset-waitall
+foreach (example activityset-testany activityset-waitany activityset-waitall activityset-waitallfor
actor-create actor-daemon actor-exiting actor-join actor-kill
actor-lifetime actor-migrate actor-suspend actor-yield actor-stacksize
app-bittorrent app-chainsend app-token-ring
--- /dev/null
+/* Copyright (c) 2010-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. */
+
+#include "simgrid/s4u.hpp"
+#include <cstdlib>
+#include <iostream>
+#include <string>
+namespace sg4 = simgrid::s4u;
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_activity_waittany, "Messages specific for this s4u example");
+
+static void bob()
+{
+ sg4::Mailbox* mbox = sg4::Mailbox::by_name("mbox");
+ const sg4::Disk* disk = sg4::Host::current()->get_disks().front();
+ std::string* payload;
+
+ XBT_INFO("Create my asynchronous activities");
+ auto exec = sg4::this_actor::exec_async(5e9);
+ auto comm = mbox->get_async(&payload);
+ auto io = disk->read_async(3e8);
+
+ sg4::ActivitySet pending_activities({exec, comm, io});
+
+ XBT_INFO("Wait for asynchrounous activities to complete");
+ while (not pending_activities.empty()) {
+ try {
+ pending_activities.wait_all_for(1);
+ } catch (simgrid::TimeoutException& e) {
+ XBT_INFO("Not all activities are terminated yet.");
+ }
+ while (auto completed_one = pending_activities.test_any()) {
+ if (boost::dynamic_pointer_cast<sg4::Comm>(completed_one))
+ XBT_INFO("Completed a Comm");
+ if (boost::dynamic_pointer_cast<sg4::Exec>(completed_one))
+ XBT_INFO("Completed an Exec");
+ if (boost::dynamic_pointer_cast<sg4::Io>(completed_one))
+ XBT_INFO("Completed an I/O");
+ }
+ }
+ XBT_INFO("Last activity is complete");
+ delete payload;
+}
+
+static void alice()
+{
+ auto* payload = new std::string("Message");
+ XBT_INFO("Send '%s'", payload->c_str());
+ sg4::Mailbox::by_name("mbox")->put(payload, 6e8);
+}
+
+int main(int argc, char* argv[])
+{
+ sg4::Engine e(&argc, argv);
+
+ e.load_platform(argv[1]);
+
+ sg4::Actor::create("bob", e.host_by_name("bob"), bob);
+ sg4::Actor::create("alice", e.host_by_name("alice"), alice);
+
+ e.run();
+
+ return 0;
+}
--- /dev/null
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/s4u-activityset-waitallfor ${platfdir}/hosts_with_disks.xml "--log=root.fmt:[%7.6r]%e[%5a]%e%m%n"
+> [0.000000] [alice] Send 'Message'
+> [0.000000] [ bob] Create my asynchronous activities
+> [0.000000] [ bob] Wait for asynchrounous activities to complete
+> [1.000000] [ bob] Not all activities are terminated yet.
+> [2.000000] [ bob] Not all activities are terminated yet.
+> [3.000000] [ bob] Not all activities are terminated yet.
+> [3.000000] [ bob] Completed an I/O
+> [4.000000] [ bob] Not all activities are terminated yet.
+> [5.000000] [ bob] Not all activities are terminated yet.
+> [5.000000] [ bob] Completed an Exec
+> [5.197828] [ bob] Completed a Comm
+> [5.197828] [ bob] Last activity is complete
/** Wait for the completion of all activities in the set, but not longer than the provided timeout
*
- * On timeout, an exception is raised, and the completed activities remain in the set. Use test_any() to retrieve
- * them.
+ * On timeout, an exception is raised.
*
- * When no timeout occures, the set is emptied.
+ * In any case, the completed activities remain in the set. Use test_any() to retrieve them.
*/
void wait_all_for(double timeout);
- /** Wait for the completion of all activities in the set. The set is emptied afterward. */
+ /** Wait for the completion of all activities in the set. The set is NOT emptied afterward. */
void wait_all() { wait_all_for(-1); }
/** Returns the first terminated activity if any, or ActivityPtr(nullptr) if no activity is terminated */
ActivityPtr test_any();
#include <simgrid/s4u/ActivitySet.hpp>
#include <simgrid/s4u/Engine.hpp>
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY(s4u_activityset, s4u_activity, "S4U set of activities");
+
namespace simgrid::s4u {
void ActivitySet::erase(ActivityPtr a)
for (const auto& act : activities_)
act->wait_until(deadline);
}
- activities_.clear();
}
ActivityPtr ActivitySet::test_any()