Merge pull request #72784 from myaaaaaaaaa/parallel-foreach

Implement parallel `foreach()` for easier multithreading
This commit is contained in:
Yuri Sizov 2023-07-14 18:48:49 +02:00
commit 2a595c26d9
4 changed files with 50 additions and 40 deletions

View file

@ -106,6 +106,32 @@ TEST_CASE("[WorkerThreadPool] Process elements using group tasks") {
}
}
TEST_CASE("[WorkerThreadPool] Parallel foreach") {
const int count_max = 256;
for (int midpoint = 0; midpoint < count_max; midpoint++) {
LocalVector<int> c;
c.resize(count_max);
for_range(0, count_max, true, String(), [&](int i) {
c[i] = 1;
});
c.sort();
CHECK(c[0] == 1);
CHECK(c[0] == c[count_max - 1]);
for_range(0, midpoint, false, String(), [&](int i) {
c[i]++;
});
for_range(midpoint, count_max, true, String(), [&](int i) {
c[i]++;
});
c.sort();
CHECK(c[0] == 2);
CHECK(c[0] == c[count_max - 1]);
}
}
} // namespace TestWorkerThreadPool
#endif // TEST_WORKER_THREAD_POOL_H