Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Slightly change the sleep duration.
[simgrid.git] / examples / msg / chord / chord.c
index a21857b..ce2c4bd 100644 (file)
@@ -38,6 +38,8 @@ static int periodic_fix_fingers_delay = 120;
 static int periodic_check_predecessor_delay = 120;
 static int periodic_lookup_delay = 10;
 
+static const double sleep_delay = 4.9999;
+
 extern long int smx_total_comms;
 
 /*
@@ -364,7 +366,7 @@ int node(int argc, char *argv[])
               random_lookup(&node);
             listen = 1;
           }else{
-            MSG_process_sleep(5);
+            MSG_process_sleep(sleep_delay);
             if(!MC_visited_reduction())
               no_op = 1;
           }
@@ -383,7 +385,7 @@ int node(int argc, char *argv[])
             next_lookup_date = MSG_get_clock() + periodic_lookup_delay;
           }else {
             // nothing to do: sleep for a while
-            MSG_process_sleep(5);
+            MSG_process_sleep(sleep_delay);
           }
         }
 
@@ -407,6 +409,9 @@ int node(int argc, char *argv[])
     }
 
     if (node.comm_receive) {
+      /* handle last task if any */
+      if (MSG_comm_wait(node.comm_receive, 0) == MSG_OK)
+        task_free(task_received);
       MSG_comm_destroy(node.comm_receive);
       node.comm_receive = NULL;
     }
@@ -514,6 +519,8 @@ static void handle_task(node_t node, msg_task_t task) {
     MSG_task_dsend(task, task_data->answer_to, task_free);
     break;
 
+  default:
+    THROW_IMPOSSIBLE;
   }
 }
 
@@ -772,7 +779,6 @@ static int remote_get_predecessor(node_t node, int ask_to)
         stop = 1;
         MSG_comm_destroy(node->comm_receive);
         node->comm_receive = NULL;
-        task_free(task_sent);
       }
       else {
         msg_task_t task_received = MSG_comm_get_task(node->comm_receive);