I have a std::vector
filled before the parallel loop with std::pair<Object, bool>
. The bools are all initialised to true
. The loop is approximately as follows:
for (int x = 0; x < xMax; ++x) // can parallelising the loop in x cause a data race?
for (int y = 0; y < yMax; ++y)
for (auto& i : vector)
if (i.first.ConstantFunctionDependingOnlyOnInput(x, y))
i.second = false;
Since we're only ever setting the bool tofalse
I don't see this causing a data-race, but I don't trust my gut on multi-threading. Operations made on the result of this bool are done in a single thread afterwards (erasing all elements where bool == true
in the vector using standard algorithms.
Advice here would be appreciated. I was going to use std::atomics
, but of course, they can't be used in a std::vector
since they're not copy-constructible.
Cheers!