Skip to content

Commit f97c91d

Browse files
committed
std.Thread: don't spin
1 parent e4abdf5 commit f97c91d

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

lib/std/Thread.zig

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

16181600
test {
1619-
// Doesn't use testing.refAllDecls() since that would pull in the compileError spinLoopHint.
16201601
_ = Futex;
16211602
_ = ResetEvent;
16221603
_ = Mutex;

0 commit comments

Comments
 (0)