diff options
| author | mochalins <117967760+mochalins@users.noreply.github.com> | 2024-07-09 11:25:19 +0900 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2024-07-09 21:15:29 -0400 |
| commit | c8e00953623bd3f4a12c8654a83a1b6cac2b2b2f (patch) | |
| tree | 162f9e336f76be637613f450c4ab0caadf99c2ec /lib | |
| parent | 6446596ba106f7ec528eab3ac64e8f3dba5dfd4f (diff) | |
| download | zig-c8e00953623bd3f4a12c8654a83a1b6cac2b2b2f.tar.gz zig-c8e00953623bd3f4a12c8654a83a1b6cac2b2b2f.zip | |
test: Add `spawn` behavior test
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/std/Thread.zig | 1 | ||||
| -rw-r--r-- | lib/std/Thread/Pool.zig | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index 25261053ee..3c2c9251d0 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -1465,6 +1465,7 @@ test { _ = Semaphore; _ = Condition; _ = RwLock; + _ = Pool; } fn testIncrementNotify(value: *usize, event: *ResetEvent) void { diff --git a/lib/std/Thread/Pool.zig b/lib/std/Thread/Pool.zig index 1a67b9735f..86bac7ce46 100644 --- a/lib/std/Thread/Pool.zig +++ b/lib/std/Thread/Pool.zig @@ -254,6 +254,27 @@ pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void { pool.cond.signal(); } +test spawn { + const TestFn = struct { + fn checkRun(completed: *bool) void { + completed.* = true; + } + }; + + var completed: bool = false; + + { + var pool: Pool = undefined; + try pool.init(.{ + .allocator = std.testing.allocator, + }); + defer pool.deinit(); + try pool.spawn(TestFn.checkRun, .{&completed}); + } + + try std.testing.expectEqual(true, completed); +} + fn worker(pool: *Pool) void { pool.mutex.lock(); defer pool.mutex.unlock(); |
