X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5fe85f0b326710124cd12cee0c57b2b0de095f10..b98b530ed10d60d9c350bf4919896a0c50b649f3:/src/include/xbt/parmap.hpp diff --git a/src/include/xbt/parmap.hpp b/src/include/xbt/parmap.hpp index 5818def7e6..00f4b8c94b 100644 --- a/src/include/xbt/parmap.hpp +++ b/src/include/xbt/parmap.hpp @@ -68,19 +68,19 @@ private: * * This function is called by the controller thread. */ - virtual void master_signal() = 0; + virtual void master_signal() = 0; /** * \brief Starts the parmap: waits for all workers to be ready and returns. * * This function is called by the controller thread. */ - virtual void master_wait() = 0; + virtual void master_wait() = 0; /** * \brief Ends the parmap: wakes the controller thread when all workers terminate. * * This function is called by all worker threads when they end (not including the controller). */ - virtual void worker_signal() = 0; + virtual void worker_signal() = 0; /** * \brief Waits for some work to process. * @@ -90,7 +90,6 @@ private: */ virtual void worker_wait(unsigned) = 0; - protected: Parmap& parmap; }; @@ -225,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 @@ -237,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); } }