authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-20 10:52:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-21 05:37:51+02:00
logf97c91ddb5ef600fce294c1bbd28e3f6f2185e5e
tree61bfcaf1af398c32314632975f1b850366aa1a6f
parente4abdf5a133ac4822644da1dabd5437ac751d78d

std.Thread: don't spin


1 files changed, 2 insertions(+), 21 deletions(-)

lib/std/Thread.zig+2-21
......@@ -911,18 +911,9 @@ const WasiThreadImpl = struct {
911911 allocator.free(self.thread.memory);
912912 }
913913
914 var spin: u8 = 10;
915914 while (true) {
916915 const tid = self.thread.tid.load(.seq_cst);
917 if (tid == 0) {
918 break;
919 }
920
921 if (spin > 0) {
922 spin -= 1;
923 std.atomic.spinLoopHint();
924 continue;
925 }
916 if (tid == 0) break;
926917
927918 const result = asm (
928919 \\ local.get %[ptr]
......@@ -1514,18 +1505,9 @@ const LinuxThreadImpl = struct {
15141505 fn join(self: Impl) void {
15151506 defer posix.munmap(self.thread.mapped);
15161507
1517 var spin: u8 = 10;
15181508 while (true) {
15191509 const tid = self.thread.child_tid.load(.seq_cst);
1520 if (tid == 0) {
1521 break;
1522 }
1523
1524 if (spin > 0) {
1525 spin -= 1;
1526 std.atomic.spinLoopHint();
1527 continue;
1528 }
1510 if (tid == 0) break;
15291511
15301512 switch (linux.E.init(linux.futex_4arg(
15311513 &self.thread.child_tid.raw,
......@@ -1616,7 +1598,6 @@ test "setName, getName" {
16161598}
16171599
16181600test {
1619 // Doesn't use testing.refAllDecls() since that would pull in the compileError spinLoopHint.
16201601 _ = Futex;
16211602 _ = ResetEvent;
16221603 _ = Mutex;