diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-09-17 21:19:01 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-17 21:19:01 -0700 |
| commit | 220c6795233bfdc9b93dfb3364b21705b1e6c903 (patch) | |
| tree | 8d59b2842374a10ceac6648f37a954b19dfa33f5 /lib/std/Thread.zig | |
| parent | 09bc118c9f2349f162f181487f8e5a01eb5e734c (diff) | |
| parent | bd4617033e09979398e65907a1d9c7f1b6e1d124 (diff) | |
| download | zig-220c6795233bfdc9b93dfb3364b21705b1e6c903.tar.gz zig-220c6795233bfdc9b93dfb3364b21705b1e6c903.zip | |
Merge pull request #25197 from rootbeer/24380-flaky-sigset-test
Re-enable std.posix "sigset_t bits" test
Diffstat (limited to 'lib/std/Thread.zig')
| -rw-r--r-- | lib/std/Thread.zig | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index c4b955c9f2..5f667497fd 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -1637,3 +1637,40 @@ test detach { event.wait(); try std.testing.expectEqual(value, 1); } + +test "Thread.getCpuCount" { + if (native_os == .wasi) return error.SkipZigTest; + + const cpu_count = try Thread.getCpuCount(); + try std.testing.expect(cpu_count >= 1); +} + +fn testThreadIdFn(thread_id: *Thread.Id) void { + thread_id.* = Thread.getCurrentId(); +} + +test "Thread.getCurrentId" { + if (builtin.single_threaded) return error.SkipZigTest; + + var thread_current_id: Thread.Id = undefined; + const thread = try Thread.spawn(.{}, testThreadIdFn, .{&thread_current_id}); + thread.join(); + try std.testing.expect(Thread.getCurrentId() != thread_current_id); +} + +test "thread local storage" { + if (builtin.single_threaded) return error.SkipZigTest; + + const thread1 = try Thread.spawn(.{}, testTls, .{}); + const thread2 = try Thread.spawn(.{}, testTls, .{}); + try testTls(); + thread1.join(); + thread2.join(); +} + +threadlocal var x: i32 = 1234; +fn testTls() !void { + if (x != 1234) return error.TlsBadStartValue; + x += 1; + if (x != 1235) return error.TlsBadEndValue; +} |
