*/
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
*/
template <typename T> void Parmap<T>::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);
}
}