Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c41fb7910819d0a8562c9f95e41e5f7963f81e63
[simgrid.git] / examples / c / actor-lifetime / actor-lifetime.c
1 /* Copyright (c) 2007-2021. 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 actor termination*/
17 static void my_onexit(int ignored1, void* ignored2)
18 {
19   XBT_INFO("Exiting now (done sleeping or got killed)."); /* - Just display an informative message (see tesh file) */
20 }
21
22 /* Just sleep until termination */
23 static void sleeper(int argc, char* argv[])
24 {
25   sg_actor_on_exit(my_onexit, NULL);
26
27   XBT_INFO("Hello! I go to sleep.");
28   sg_actor_sleep_for(10);
29   XBT_INFO("Done sleeping.");
30 }
31
32 int main(int argc, char* argv[])
33 {
34   simgrid_init(&argc, argv);
35   xbt_assert(argc > 2,
36              "Usage: %s platform_file deployment_file\n"
37              "\tExample: %s platform.xml deployment.xml\n",
38              argv[0], argv[0]);
39
40   simgrid_load_platform(argv[1]); /* - Load the platform description */
41   simgrid_register_function("sleeper", sleeper);
42   simgrid_load_deployment(argv[2]); /* - Deploy the sleeper actors with explicit start/kill times */
43
44   simgrid_run(); /* - Run the simulation */
45
46   return 0;
47 }