I'm trying to parallelize the following function (pseudocode):
vector<int32> out; for (int32 i = 0; i < 10; ++i) { int32 result = multiplyStuffByTwo(i); // Push to results out.push_back(result); } When I now parallelize the for loop and define the push_back part as a critical path, I'm encountering the problem that (of course) the order of the results in out is not always right. How can I make the threads run execute the code in the right order in the last line of the for loop? Thanks!