Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert and simplify msg/process-lifetime
[simgrid.git] / examples / c / actor-lifetime / actor-lifetime.c
1 /* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/actor.h"
7 #include "simgrid/engine.h"
8
9 #include "xbt/asserts.h"
10 #include "xbt/log.h"
11
12 #include <stdio.h> /* snprintf */
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific for this example");
15
16 /* Executed on process termination*/
17 static int my_onexit(XBT_ATTRIB_UNUSED int ignored1, XBT_ATTRIB_UNUSED void* ignored2)
18 {
19   XBT_INFO("Exiting now (done sleeping or got killed)."); /* - Just display an informative message (see tesh file) */
20   return 0;
21 }
22
23 /* Just sleep until termination */
24 static void sleeper(int argc, char* argv[])
25 {
26   sg_actor_on_exit(my_onexit, NULL);
27
28   XBT_INFO("Hello! I go to sleep.");
29   sg_actor_sleep_for(10);
30   XBT_INFO("Done sleeping.");
31 }
32
33 int main(int argc, char* argv[])
34 {
35   simgrid_init(&argc, argv);
36   xbt_assert(argc > 2,
37              "Usage: %s platform_file deployment_file\n"
38              "\tExample: %s msg_platform.xml msg_deployment.xml\n",
39              argv[0], argv[0]);
40
41   simgrid_load_platform(argv[1]); /* - Load the platform description */
42   simgrid_register_function("sleeper", sleeper);
43   simgrid_load_deployment(argv[2]); /* - Deploy the sleeper processes with explicit start/kill times */
44
45   simgrid_run(); /* - Run the simulation */
46
47   return 0;
48 }