Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / examples / deprecated / msg / platform-failures / platform-failures.c
index 229a929..542f034 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-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. */
@@ -11,8 +11,14 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example")
 
 #define FINALIZE ((void*)221297)        /* a magic number to tell people to stop working */
 
+static void task_cleanup_handler(void* task)
+{
+  MSG_task_destroy(task);
+}
+
 static int master(int argc, char *argv[])
 {
+  xbt_assert(argc == 5);
   long number_of_tasks = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
   double task_comp_size = xbt_str_parse_double(argv[2], "Invalid computational size: %s");
   double task_comm_size = xbt_str_parse_double(argv[3], "Invalid communication size: %s");
@@ -32,7 +38,7 @@ static int master(int argc, char *argv[])
       break;
 
     case MSG_TRANSFER_FAILURE:
-      XBT_INFO("Mmh. Something went wrong with '%s'. Nevermind. Let's keep going!", mailbox);
+      XBT_INFO("Mmh. The communication with '%s' failed. Nevermind. Let's keep going!", mailbox);
       MSG_task_destroy(task);
       break;
 
@@ -79,6 +85,7 @@ static int master(int argc, char *argv[])
 
 static int worker(int argc, char *argv[])
 {
+  xbt_assert(argc == 2);
   char mailbox[80];
 
   long id= xbt_str_parse_int(argv[1], "Invalid argument %s");
@@ -95,7 +102,9 @@ static int worker(int argc, char *argv[])
         break;
       }
       XBT_INFO("Start execution...");
+      MSG_process_set_data(MSG_process_self(), task);
       retcode = MSG_task_execute(task);
+      MSG_process_set_data(MSG_process_self(), NULL);
       if (retcode == MSG_OK) {
         XBT_INFO("Execution complete.");
         MSG_task_destroy(task);
@@ -123,6 +132,7 @@ int main(int argc, char *argv[])
 
   MSG_function_register("master", master);
   MSG_function_register("worker", worker);
+  MSG_process_set_data_cleanup(task_cleanup_handler);
   MSG_launch_application(argv[2]);
 
   msg_error_t res = MSG_main();