X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0746edb369906f57c331d9336bf85ae91094ad51..0bfafcab47ae9cd7856bd8d129404c33079d6afe:/examples/cpp/actor-stacksize/s4u-actor-stacksize.cpp diff --git a/examples/cpp/actor-stacksize/s4u-actor-stacksize.cpp b/examples/cpp/actor-stacksize/s4u-actor-stacksize.cpp new file mode 100644 index 0000000000..c1842157c8 --- /dev/null +++ b/examples/cpp/actor-stacksize/s4u-actor-stacksize.cpp @@ -0,0 +1,45 @@ +/* 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. */ + +/* This code tests that we can change the stack-size between the actors creation. */ + +#include +namespace sg4 = simgrid::s4u; + +XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); + +static void actor() +{ + XBT_INFO("Hello"); +} + +int main(int argc, char* argv[]) +{ + sg4::Engine e(&argc, argv); + e.load_platform(argv[1]); + + // If you don't specify anything, you get the default size (8Mb) or the one passed on the command line + sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor); + + // You can use set_config(string) to pass a size that will be parsed. That value will be used for any subsequent + // actors + sg4::Engine::set_config("contexts/stack-size:16384"); + sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor); + sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor); + + // You can use set_config(key, value) for the same effect. + sg4::Engine::set_config("contexts/stack-size", 32 * 1024); + sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor); + sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor); + + // Or you can use set_stacksize() before starting the actor to modify only this one + sg4::Actor::init("actor", sg4::Host::by_name("Tremblay"))->set_stacksize(64 * 1024)->start(actor); + sg4::Actor::create("actor", sg4::Host::by_name("Tremblay"), actor); + + e.run(); + XBT_INFO("Simulation time %g", e.get_clock()); + + return 0; +}