Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Be safe in case of spurious wakeup of xbt_os_cond_wait.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Oct 2017 11:13:56 +0000 (12:13 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 30 Oct 2017 14:44:29 +0000 (15:44 +0100)
src/include/xbt/parmap.hpp

index 35a7e06..3eeb6a2 100644 (file)
@@ -338,7 +338,7 @@ template <typename T> void Parmap<T>::PosixSynchro::master_signal()
 template <typename T> void Parmap<T>::PosixSynchro::master_wait()
 {
   xbt_os_mutex_acquire(done_mutex);
-  if (this->parmap.thread_counter < this->parmap.num_workers) {
+  while (this->parmap.thread_counter < this->parmap.num_workers) {
     /* wait for all workers to be ready */
     xbt_os_cond_wait(done_cond, done_mutex);
   }
@@ -360,7 +360,7 @@ template <typename T> void Parmap<T>::PosixSynchro::worker_wait(unsigned round)
 {
   xbt_os_mutex_acquire(ready_mutex);
   /* wait for more work */
-  if (this->parmap.work_round != round) {
+  while (this->parmap.work_round != round) {
     xbt_os_cond_wait(ready_cond, ready_mutex);
   }
   xbt_os_mutex_release(ready_mutex);