Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
spelling mistakes in include/ and examples/
[simgrid.git] / examples / c / actor-create / actor-create.c
index 829a190..47e65cf 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2018. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2020. 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. */
@@ -7,7 +7,7 @@
  *
  * The first step is to declare the code of your actors (what they do exactly does not matter to this example) and then
  * you ask SimGrid to start your actors. There is three ways of doing so:
- *  - Directly, by instantiating your actor as paramter to Actor::create()
+ *  - Directly, by instantiating your actor as parameter to Actor::create()
  *  - By first registering your actors before instantiating it;
  *  - Through the deployment file.
  *
@@ -39,10 +39,13 @@ static void receiver(int argc, char** argv)
 
   XBT_INFO("Hello, I'm ready to get any message you'd want on %s", argv[1]);
 
-  const char* msg1 = sg_mailbox_get(mailbox);
-  const char* msg2 = sg_mailbox_get(mailbox);
-  const char* msg3 = sg_mailbox_get(mailbox);
+  char* msg1 = sg_mailbox_get(mailbox);
+  char* msg2 = sg_mailbox_get(mailbox);
+  char* msg3 = sg_mailbox_get(mailbox);
   XBT_INFO("I received '%s', '%s' and '%s'", msg1, msg2, msg3);
+  xbt_free(msg1);
+  xbt_free(msg2);
+  xbt_free(msg3);
   XBT_INFO("I'm done. See you.");
 }
 
@@ -51,8 +54,8 @@ static void sender(int argc, char** argv)
 {
   xbt_assert(argc == 3, "Actor 'sender' requires 2 parameters (mailbox and data to send), but got only %d", argc - 1);
   XBT_INFO("Hello, I have something to send");
-  char* sent_data      = argv[1];
-  sg_mailbox_t mailbox = sg_mailbox_by_name(argv[2]);
+  const char* sent_data = argv[1];
+  sg_mailbox_t mailbox  = sg_mailbox_by_name(argv[2]);
 
   sg_mailbox_put(mailbox, xbt_strdup(sent_data), strlen(sent_data));
   XBT_INFO("I'm done. See you.");
@@ -63,7 +66,7 @@ static void forwarder(int argc, char** argv)
   xbt_assert(argc >= 3, "Actor forwarder requires 2 parameters, but got only %d", argc - 1);
   sg_mailbox_t mailbox_in  = sg_mailbox_by_name(argv[1]);
   sg_mailbox_t mailbox_out = sg_mailbox_by_name(argv[2]);
-  char* msg                = (char*)(sg_mailbox_get(mailbox_in));
+  char* msg                = sg_mailbox_get(mailbox_in);
   XBT_INFO("Forward '%s'.", msg);
   sg_mailbox_put(mailbox_out, msg, strlen(msg));
 }
@@ -81,17 +84,15 @@ int main(int argc, char** argv)
    *
    * The easiest way to do so is to implement the behavior of your actor in a single function,
    * as we do here for the receiver actors. This function can take any kind of parameters, as
-   * long as the last parameters of Actor::create() match what your function expects.
+   * long as the last parameters of sg_actor_create() or sg_actor_start() match what your function expects.
    */
   int recv_argc           = 2;
   const char* recv_argv[] = {"receiver", "mb42", NULL};
-  sg_actor_t recv         = sg_actor_init("receiver", sg_host_by_name("Fafard"));
-  sg_actor_start(recv, receiver, recv_argc, recv_argv);
+  sg_actor_create("receiver", sg_host_by_name("Fafard"), receiver, recv_argc, recv_argv);
 
   int sender1_argc           = 3;
   const char* sender1_argv[] = {"sender", "GaBuZoMeu", "mb42", NULL};
-  sg_actor_t sender1         = sg_actor_init("sender1", sg_host_by_name("Tremblay"));
-  sg_actor_start(sender1, sender, sender1_argc, sender1_argv);
+  sg_actor_create("sender1", sg_host_by_name("Tremblay"), sender, sender1_argc, sender1_argv);
 
   int sender2_argc           = 3;
   const char* sender2_argv[] = {"sender", "GloubiBoulga", "mb42", NULL};