commit 36c390bf1484a9a549759663a2bbb9bbe82f6706 (tree)
parent b4d134a0d2ee238cab70f1e967b2172edbec1b41
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date: Thu, 19 Mar 2026 16:48:24 +0000
Zcu: correctly handle tid when main thread recurses
Resolves: https://codeberg.org/ziglang/zig/issues/31380
Diffstat:
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig
@@ -69,19 +69,26 @@ pub const Id = if (InternPool.single_threaded) enum {
/// will likely involve significant changes to the `InternPool` implementation.
var available_tids: std.ArrayList(Id) = .empty;
threadlocal var recursive_depth: usize = 0;
- threadlocal var recursive_tid: Id = .main;
+ threadlocal var recursive_tid: Id = undefined;
pub fn allocate(arena: Allocator, n: usize) Allocator.Error!void {
assert(available_tids.items.len == 0);
try available_tids.ensureTotalCapacityPrecise(arena, n - 1);
for (1..n) |tid| available_tids.appendAssumeCapacity(@enumFromInt(tid));
+ switch (build_options.io_mode) {
+ .threaded => {
+ // Called from the main thread, so mark ourselves as such.
+ recursive_depth = 1;
+ recursive_tid = .main;
+ },
+ .evented => {},
+ }
}
pub fn acquire(io: std.Io) Id {
switch (build_options.io_mode) {
.threaded => {
recursive_depth += 1;
if (recursive_depth > 1) {
- assert(recursive_tid != .main);
return recursive_tid;
}
},
@@ -106,7 +113,6 @@ pub const Id = if (InternPool.single_threaded) enum {
assert(recursive_tid == tid);
recursive_depth -= 1;
if (recursive_depth > 0) return;
- recursive_tid = .main;
},
.evented => {},
}