| 171 | } concurrency_ctx_t; |
| 172 | |
| 173 | static void concurrency_worker(int idx, void *ctx_ptr) { |
| 174 | (void)idx; |
| 175 | concurrency_ctx_t *cc = ctx_ptr; |
| 176 | int cur = atomic_fetch_add(&cc->concurrent_now, 1) + 1; |
| 177 | /* Spin until at least two workers are concurrently active, so overlap is |
| 178 | * demonstrated deterministically instead of depending on thread-spawn timing |
| 179 | * (a fixed busy-wait flaked on loaded runners when a worker finished before |
| 180 | * the next started). Bounded so it can't hang if real parallelism is absent. */ |
| 181 | for (long spins = 0; spins < 200000000L; spins++) { |
| 182 | if (atomic_load(&cc->concurrent_now) >= 2 || atomic_load(&cc->concurrent_max) >= 2) |
| 183 | break; |
| 184 | } |
| 185 | /* Record max */ |
| 186 | int prev_max = atomic_load(&cc->concurrent_max); |
| 187 | while (cur > prev_max) { |
| 188 | if (atomic_compare_exchange_weak(&cc->concurrent_max, &prev_max, cur)) |
| 189 | break; |
| 190 | } |
| 191 | atomic_fetch_sub(&cc->concurrent_now, 1); |
| 192 | } |
| 193 | |
| 194 | TEST(parallel_for_actually_parallel) { |
| 195 | concurrency_ctx_t cc; |
nothing calls this directly
no outgoing calls
no test coverage detected