From 326d152a10a4c9907e5e54f104f253155abdc851 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 30 Aug 2017 17:27:50 +0200 Subject: [PATCH] Use std::atomic::fetch_add instead of ++ shortcut (clearer to the reader). --- src/include/xbt/parmap.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/include/xbt/parmap.hpp b/src/include/xbt/parmap.hpp index bc65ff9274..00f4b8c94b 100644 --- a/src/include/xbt/parmap.hpp +++ b/src/include/xbt/parmap.hpp @@ -224,7 +224,7 @@ template void Parmap::apply(void (*fun)(T), const std::vector */ template boost::optional Parmap::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 @@ -236,11 +236,11 @@ template boost::optional Parmap::next() */ template void Parmap::work() { - unsigned index = this->index++; unsigned length = this->data->size(); + unsigned index = this->index.fetch_add(1, std::memory_order_relaxed); while (index < length) { this->fun((*this->data)[index]); - index = this->index++; + index = this->index.fetch_add(1, std::memory_order_relaxed); } } -- 2.20.1