mirror of
https://github.com/DeusData/codebase-memory-mcp.git
synced 2026-11-04 10:48:20 +00:00
Make parallel_for_actually_parallel deterministic
The test proved parallelism with a fixed 10000-iteration busy-wait, hoping workers would overlap — but on a loaded CI runner a worker could finish before the next thread started, leaving concurrent_max=1 (a flaky FAIL, seen on ubuntu-latest). Spin until at least two workers are concurrently active (bounded, with an early exit once the overlap is proven) so the parallelism invariant is demonstrated deterministically instead of by timing luck.
This commit is contained in:
1 parent
a2c9804397
commit
4207c83679
1 file changed
+8
-5
@@ -174,11 +174,14 @@ static void concurrency_worker(int idx, void *ctx_ptr) {
|
|||||||
(void)idx;
|
(void)idx;
|
||||||
concurrency_ctx_t *cc = ctx_ptr;
|
concurrency_ctx_t *cc = ctx_ptr;
|
||||||
int cur = atomic_fetch_add(&cc->concurrent_now, 1) + 1;
|
int cur = atomic_fetch_add(&cc->concurrent_now, 1) + 1;
|
||||||
/* Brief busy-wait to let others start */
|
/* Spin until at least two workers are concurrently active, so overlap is
|
||||||
volatile int x = 0;
|
* demonstrated deterministically instead of depending on thread-spawn timing
|
||||||
for (int j = 0; j < 10000; j++)
|
* (a fixed busy-wait flaked on loaded runners when a worker finished before
|
||||||
x++;
|
* the next started). Bounded so it can't hang if real parallelism is absent. */
|
||||||
(void)x;
|
for (long spins = 0; spins < 200000000L; spins++) {
|
||||||
|
if (atomic_load(&cc->concurrent_now) >= 2 || atomic_load(&cc->concurrent_max) >= 2)
|
||||||
|
break;
|
||||||
|
}
|
||||||
/* Record max */
|
/* Record max */
|
||||||
int prev_max = atomic_load(&cc->concurrent_max);
|
int prev_max = atomic_load(&cc->concurrent_max);
|
||||||
while (cur > prev_max) {
|
while (cur > prev_max) {
|
||||||
|
|||||||
Reference in new issue
Block a user