From 8ea2b40e5f621482d714fdd7cb05bbc592fc550b Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 11 Jan 2021 22:23:03 -0700 Subject: [PATCH] std.event.Loop: fix race condition when starting the time wheel closes #7572 --- lib/std/event/loop.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index f5df637f37..8101d27a55 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -796,9 +796,10 @@ pub const Loop = struct { .waiters = DelayQueue.Waiters{ .entries = std.atomic.Queue(anyframe).init(), }, - .thread = try std.Thread.spawn(self, DelayQueue.run), .event = std.AutoResetEvent{}, .is_running = true, + // Must be last so that it can read the other state, such as `is_running`. + .thread = try std.Thread.spawn(self, DelayQueue.run), }; }