Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use std::atomic::fetch_add instead of ++ shortcut (clearer to the reader).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 30 Aug 2017 15:27:50 +0000 (17:27 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 30 Aug 2017 15:27:50 +0000 (17:27 +0200)
src/include/xbt/parmap.hpp

index bc65ff9..00f4b8c 100644 (file)
@@ -224,7 +224,7 @@ template <typename T> void Parmap<T>::apply(void (*fun)(T), const std::vector<T>
  */
 template <typename T> boost::optional<T> Parmap<T>::next()
 {
  */
 template <typename T> boost::optional<T> Parmap<T>::next()
 {
-  unsigned index = this->index++;
+  unsigned index = this->index.fetch_add(1, std::memory_order_relaxed);
   if (index < this->data->size())
     return (*this->data)[index];
   else
   if (index < this->data->size())
     return (*this->data)[index];
   else
@@ -236,11 +236,11 @@ template <typename T> boost::optional<T> Parmap<T>::next()
  */
 template <typename T> void Parmap<T>::work()
 {
  */
 template <typename T> void Parmap<T>::work()
 {
-  unsigned index = this->index++;
   unsigned length = this->data->size();
   unsigned length = this->data->size();
+  unsigned index  = this->index.fetch_add(1, std::memory_order_relaxed);
   while (index < length) {
     this->fun((*this->data)[index]);
   while (index < length) {
     this->fun((*this->data)[index]);
-    index = this->index++;
+    index = this->index.fetch_add(1, std::memory_order_relaxed);
   }
 }
 
   }
 }