Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reindent a bunch of deployment files too
[simgrid.git] / examples / msg / app-masterworker / app-masterworker.c
index 0640633..ee480f1 100644 (file)
@@ -24,8 +24,8 @@ static int master(int argc, char *argv[])
     char mailbox[256];
     char task_name[256];
 
-    sprintf(mailbox, "worker-%ld", i % workers_count); /* - Select a @ref worker in a round-robin way */
-    sprintf(task_name, "Task_%d", i);
+    snprintf(mailbox,255, "worker-%ld", i % workers_count); /* - Select a @ref worker in a round-robin way */
+    snprintf(task_name,255, "Task_%d", i);
     msg_task_t task = MSG_task_create(task_name, comp_size, comm_size, NULL);   /* - Create a task */
     if (number_of_tasks < 10000 || i % 10000 == 0)
       XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", task->name, number_of_tasks, mailbox);
@@ -37,7 +37,7 @@ static int master(int argc, char *argv[])
   for (i = 0; i < workers_count; i++) { /* - Eventually tell all the workers to stop by sending a "finalize" task */
     char mailbox[80];
 
-    sprintf(mailbox, "worker-%ld", i % workers_count);
+    snprintf(mailbox,79, "worker-%ld", i % workers_count);
     msg_task_t finalize = MSG_task_create("finalize", 0, 0, 0);
     MSG_task_send(finalize, mailbox);
   }
@@ -53,20 +53,17 @@ static int worker(int argc, char *argv[])
 
   long id= xbt_str_parse_int(argv[1], "Invalid argument %s");
 
-  sprintf(mailbox, "worker-%ld", id);
+  snprintf(mailbox,79, "worker-%ld", id);
 
   while (1) {  /* The worker wait in an infinite loop for tasks sent by the \ref master */
     int res = MSG_task_receive(&(task), mailbox);
     xbt_assert(res == MSG_OK, "MSG_task_get failed");
 
-//  XBT_INFO("Received \"%s\"", MSG_task_get_name(task));
-    if (!strcmp(MSG_task_get_name(task), "finalize")) {
+    if (strcmp(MSG_task_get_name(task), "finalize") == 0) {
       MSG_task_destroy(task);  /* - Exit if 'finalize' is received */
       break;
     }
-//    XBT_INFO("Processing \"%s\"", MSG_task_get_name(task));
     MSG_task_execute(task);    /*  - Otherwise, process the task */
-//    XBT_INFO("\"%s\" done", MSG_task_get_name(task));
     MSG_task_destroy(task);
     task = NULL;
   }