diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-07-20 10:52:04 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-07-21 05:37:51 +0200 |
| commit | f97c91ddb5ef600fce294c1bbd28e3f6f2185e5e (patch) | |
| tree | 61bfcaf1af398c32314632975f1b850366aa1a6f /lib/std/Thread.zig | |
| parent | e4abdf5a133ac4822644da1dabd5437ac751d78d (diff) | |
| download | zig-f97c91ddb5ef600fce294c1bbd28e3f6f2185e5e.tar.gz zig-f97c91ddb5ef600fce294c1bbd28e3f6f2185e5e.zip | |
std.Thread: don't spin
Diffstat (limited to 'lib/std/Thread.zig')
| -rw-r--r-- | lib/std/Thread.zig | 23 |
1 files changed, 2 insertions, 21 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 7438c3d908..63af3796b7 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -911,18 +911,9 @@ const WasiThreadImpl = struct { allocator.free(self.thread.memory); } - var spin: u8 = 10; while (true) { const tid = self.thread.tid.load(.seq_cst); - if (tid == 0) { - break; - } - - if (spin > 0) { - spin -= 1; - std.atomic.spinLoopHint(); - continue; - } + if (tid == 0) break; const result = asm ( \\ local.get %[ptr] @@ -1514,18 +1505,9 @@ const LinuxThreadImpl = struct { fn join(self: Impl) void { defer posix.munmap(self.thread.mapped); - var spin: u8 = 10; while (true) { const tid = self.thread.child_tid.load(.seq_cst); - if (tid == 0) { - break; - } - - if (spin > 0) { - spin -= 1; - std.atomic.spinLoopHint(); - continue; - } + if (tid == 0) break; switch (linux.E.init(linux.futex_4arg( &self.thread.child_tid.raw, @@ -1616,7 +1598,6 @@ test "setName, getName" { } test { - // Doesn't use testing.refAllDecls() since that would pull in the compileError spinLoopHint. _ = Futex; _ = ResetEvent; _ = Mutex; |
