]> AND Private Git Repository - loba.git/blobdiff - process.cpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Neighbor/debt should be protected against concurrent access too.
[loba.git] / process.cpp
index d0bfc21120b8cbc8ea0230b4eb9bb97e4eeb26f3..21eeb7a194373fdd0b195698dac4360100220f0e 100644 (file)
@@ -21,7 +21,7 @@ double process::total_load_exit = 0.0;
 
 namespace {
 
 
 namespace {
 
-    void sleep_until_date(double& date, double duration = 0.0)
+    void sleep_until_date(double& date, double duration)
     {
         double sleep_duration = date - MSG_get_clock();
         if (sleep_duration > 0.0)
     {
         double sleep_duration = date - MSG_get_clock();
         if (sleep_duration > 0.0)
@@ -126,6 +126,7 @@ void process::load_balance_loop()
             ++lb_iter;
         }
 
             ++lb_iter;
         }
 
+        mutex.acquire();
         if (!opt::bookkeeping)
             expected_load = real_load - get_sum_of_to_send();
         // nothing to do with opt::bookkeeping
         if (!opt::bookkeeping)
             expected_load = real_load - get_sum_of_to_send();
         // nothing to do with opt::bookkeeping
@@ -144,6 +145,7 @@ void process::load_balance_loop()
         std::for_each(neigh.begin(), neigh.end(),
                       bind(&process::ctrl_send, this, _1));
         prev_load_broadcast = expected_load;
         std::for_each(neigh.begin(), neigh.end(),
                       bind(&process::ctrl_send, this, _1));
         prev_load_broadcast = expected_load;
+        mutex.release();
 
         sleep_until_date(next_iter_after_date, opt::min_lb_iter_duration);
         ctrl_receive(0.0);
 
         sleep_until_date(next_iter_after_date, opt::min_lb_iter_duration);
         ctrl_receive(0.0);
@@ -172,19 +174,23 @@ void process::compute_loop()
     double next_iter_after_date = MSG_get_clock() + opt::min_comp_iter_duration;
     while (still_running()) {
         // receive
     double next_iter_after_date = MSG_get_clock() + opt::min_comp_iter_duration;
     while (still_running()) {
         // receive
+        mutex.acquire();
         if (real_load > 0.0)
             data_receive(0.0);
         else
             data_receive(opt::min_comp_iter_duration);
         if (real_load > 0.0)
             data_receive(0.0);
         else
             data_receive(opt::min_comp_iter_duration);
+        mutex.release();
 
         comm.data_flush(false);
 
 
         comm.data_flush(false);
 
-        if (real_load == 0.0)
-            continue;
-
         // send
         // send
+        mutex.acquire();
         std::for_each(neigh.begin(), neigh.end(),
                       bind(&process::data_send, this, _1));
         std::for_each(neigh.begin(), neigh.end(),
                       bind(&process::data_send, this, _1));
+        mutex.release();
+
+        if (real_load == 0.0)
+            continue;
 
         // compute
         ++comp_iter;
 
         // compute
         ++comp_iter;
@@ -224,6 +230,10 @@ bool process::still_running()
     if (!last_status) {
         /* nop */
 
     if (!last_status) {
         /* nop */
 
+    } else if (opt::exit_request) {
+        XBT_VERB("Global exit requested");
+        last_status = false;
+
     } else if (opt::time_limit && MSG_get_clock() >= opt::time_limit) {
         XBT_VERB("Reached time limit: %g/%g", MSG_get_clock(), opt::time_limit);
         last_status = false;
     } else if (opt::time_limit && MSG_get_clock() >= opt::time_limit) {
         XBT_VERB("Reached time limit: %g/%g", MSG_get_clock(), opt::time_limit);
         last_status = false;