diff options
author | myaaaaaaaaa <103326468+myaaaaaaaaa@users.noreply.github.com> | 2023-02-06 00:23:45 -0500 |
---|---|---|
committer | myaaaaaaaaa <103326468+myaaaaaaaaa@users.noreply.github.com> | 2023-06-09 08:27:32 -0400 |
commit | e28868e30cd478e878d0a8331e17e2cf90039558 (patch) | |
tree | 759c0da9d10b3700ab2c5fcd85b207eb7369b6cf /tests/core/threads | |
parent | 828ec2c5d005b6499c7c4c88beaf81767d05614b (diff) | |
download | redot-engine-e28868e30cd478e878d0a8331e17e2cf90039558.tar.gz |
Implement parallel foreach() for easier multithreading
Diffstat (limited to 'tests/core/threads')
-rw-r--r-- | tests/core/threads/test_worker_thread_pool.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/core/threads/test_worker_thread_pool.h b/tests/core/threads/test_worker_thread_pool.h index e9a762b57b..ef0b475715 100644 --- a/tests/core/threads/test_worker_thread_pool.h +++ b/tests/core/threads/test_worker_thread_pool.h @@ -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 |