From 4b9d12708e5318221e43fabd955a27a339a37c6c Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Fri, 17 May 2024 23:21:38 +0200 Subject: [PATCH] Loop run waits until pingers finish This ensures that if somebody passes an event to a loop which has just started executing, then the event gets picked up. Otherwise there is a race condition causing stray events pending in queue but without the ping (because the run actually finishes too fast to pickup the later events). --- sysdep/unix/io-loop.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sysdep/unix/io-loop.c b/sysdep/unix/io-loop.c index 5d73b445e..96aab7e6a 100644 --- a/sysdep/unix/io-loop.c +++ b/sysdep/unix/io-loop.c @@ -1472,6 +1472,17 @@ birdloop_run(void *_loop) account_to(&loop->locking); birdloop_enter(loop); this_birdloop = loop; + + /* Wait until pingers end to wait for all events to actually arrive */ + for (u32 ltt; + ltt = atomic_load_explicit(&loop->thread_transition, memory_order_acquire); + ) + { + ASSERT_DIE(ltt == LTT_PING); + birdloop_yield(); + } + + /* Now we can actually do some work */ u64 dif = account_to(&loop->working); if (dif > this_thread->max_loop_time_ns) -- 2.47.2