Commit 8ea2b40e5f

Andrew Kelley <andrew@ziglang.org>
2021-01-12 06:23:03
std.event.Loop: fix race condition when starting the time wheel
closes #7572
1 parent 0edde40
Changed files (1)
lib
std
event
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),
             };
         }