X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/9a94db9ebea7a49f58308560099411d4ab59b183..6ae04e68aa7838418bdf7cafdba4a1f5700db814:/examples/c/actor-exiting/actor-exiting.c diff --git a/examples/c/actor-exiting/actor-exiting.c b/examples/c/actor-exiting/actor-exiting.c index cde29b7bea..e32bec0be5 100644 --- a/examples/c/actor-exiting/actor-exiting.c +++ b/examples/c/actor-exiting/actor-exiting.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2017-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2017-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. */ @@ -19,24 +19,49 @@ #include #include #include +#include #include #include XBT_LOG_NEW_DEFAULT_CATEGORY(actor_exiting, "Messages specific for this example"); -static int my_on_exit(XBT_ATTRIB_UNUSED int ignored1, XBT_ATTRIB_UNUSED void* ignored2) +static void A_on_exit(int ignored1, void* ignored2) { XBT_INFO("I stop now"); - return 0; } -static void actor_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[]) +static void actorA_fun(int argc, char* argv[]) +{ + // Register a lambda function to be executed once it stops + sg_actor_on_exit(&A_on_exit, NULL); + + sg_actor_sleep_for(1); +} +static void actorB_fun(int argc, char* argv[]) +{ + sg_actor_sleep_for(2); +} +static void C_on_exit(int failed, void* ignored2) +{ + if (failed) { + XBT_INFO("I was killed!"); + if (xbt_log_no_loc) + XBT_INFO("The backtrace would be displayed here if --log=no_loc would not have been passed"); + else + xbt_backtrace_display_current(); + } else + XBT_INFO("Exiting gracefully."); +} +static void actorC_fun(int argc, char* argv[]) { // Register a lambda function to be executed once it stops - sg_actor_on_exit(&my_on_exit, NULL); + sg_actor_on_exit(&C_on_exit, NULL); - sg_actor_execute(1e9); + sg_actor_sleep_for(3); + XBT_INFO("And now, induce a deadlock by waiting for a message that will never come\n\n"); + sg_mailbox_get(sg_mailbox_by_name("nobody")); + xbt_die("Receiving is not supposed to succeed when nobody is sending"); } int main(int argc, char* argv[]) @@ -46,8 +71,9 @@ int main(int argc, char* argv[]) simgrid_load_platform(argv[1]); /* - Load the platform description */ - sg_actor_t actor = sg_actor_init("A", sg_host_by_name("Tremblay")); - sg_actor_start(actor, actor_fun, 0, NULL); + sg_actor_create("A", sg_host_by_name("Tremblay"), actorA_fun, 0, NULL); + sg_actor_create("B", sg_host_by_name("Fafard"), actorB_fun, 0, NULL); + sg_actor_create("C", sg_host_by_name("Ginette"), actorC_fun, 0, NULL); simgrid_run();