From 8c54637f8c7a98bbaec6ee38229a904bbf22170c Mon Sep 17 00:00:00 2001 From: Shirui Cheng Date: Thu, 22 Aug 2024 21:58:58 -0700 Subject: [PATCH] Better trigger race condition in bin_batching unit test --- test/unit/bin_batching.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/unit/bin_batching.c b/test/unit/bin_batching.c index 525f59e0..19975341 100644 --- a/test/unit/bin_batching.c +++ b/test/unit/bin_batching.c @@ -45,9 +45,16 @@ increment_push_failure(size_t push_idx) { atomic_fetch_add_zu(&push_failure_count, 1, ATOMIC_RELAXED); } else { assert_zu_lt(push_idx, 4, "Only 4 elems"); - volatile int x = 10000; + volatile size_t x = 10000; while (--x) { /* Spin for a while, to try to provoke a failure. */ + if (x == push_idx) { +#ifdef _WIN32 + SwitchToThread(); +#else + sched_yield(); +#endif + } } } }