]> AND Public Git Repository - simgrid.git/blobdiff - examples/c/async-waitany/async-waitany.c
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a tesh for bugged2-liveness
[simgrid.git] / examples / c / async-waitany / async-waitany.c
index cfe912776d8bc373a4510ad51c5811bc5b5970df..14a0767470c820d3b1bf4fa1c0e21253758aba70 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(async_waitany, "Messages specific for this example");
 
-static int sender(int argc, char* argv[])
+static void sender(int argc, char* argv[])
 {
   xbt_assert(argc == 4, "Expecting 3 parameters from the XML deployment file but got %d", argc);
-  long messages_count  = xbt_str_parse_int(argv[1], "Invalid amount of tasks: %s");
-  long msg_size        = xbt_str_parse_int(argv[2], "Invalid communication size: %s");
+  long messages_count  = xbt_str_parse_int(argv[1], "Invalid message count: %s");
+  long msg_size        = xbt_str_parse_int(argv[2], "Invalid message size: %s");
   long receivers_count = xbt_str_parse_int(argv[3], "Invalid amount of receivers: %s");
 
   /* Array in which we store all ongoing communications */
-  sg_comm_t* pending_comms = malloc(sizeof(sg_comm_t) * (messages_count + receivers_count));
+  sg_comm_t* pending_comms = xbt_malloc(sizeof(sg_comm_t) * (messages_count + receivers_count));
   int pending_comms_count  = 0;
 
   /* Make an array of the mailboxes to use */
-  sg_mailbox_t* mboxes = malloc(sizeof(sg_mailbox_t) * receivers_count);
+  sg_mailbox_t* mboxes = xbt_malloc(sizeof(sg_mailbox_t) * receivers_count);
   for (long i = 0; i < receivers_count; i++) {
     char mailbox_name[80];
     snprintf(mailbox_name, 79, "receiver-%ld", i);
@@ -63,7 +63,7 @@ static int sender(int argc, char* argv[])
    * Even in this simple example, the pending comms do not terminate in the exact same order of creation.
    */
   while (pending_comms_count != 0) {
-    int changed_pos = sg_comm_wait_any_for(pending_comms, pending_comms_count, -1);
+    int changed_pos = sg_comm_wait_any(pending_comms, pending_comms_count);
     memmove(pending_comms + changed_pos, pending_comms + changed_pos + 1,
             sizeof(sg_comm_t) * (pending_comms_count - changed_pos - 1));
     pending_comms_count--;
@@ -77,10 +77,9 @@ static int sender(int argc, char* argv[])
   free(mboxes);
 
   XBT_INFO("Goodbye now!");
-  return 0;
 }
 
-static int receiver(int argc, char* argv[])
+static void receiver(int argc, char* argv[])
 {
   xbt_assert(argc == 2, "Expecting one parameter from the XML deployment file but got %d", argc);
   int id = xbt_str_parse_int(argv[1], "ID should be numerical, not %s");
@@ -99,7 +98,6 @@ static int receiver(int argc, char* argv[])
   }
 
   XBT_INFO("I'm done. See you!");
-  return 0;
 }
 
 int main(int argc, char* argv[])
@@ -117,7 +115,6 @@ int main(int argc, char* argv[])
   simgrid_load_deployment(argv[2]);
 
   simgrid_run();
-
   XBT_INFO("Simulation time %g", simgrid_get_clock());
 
   return 0;