| ... | ... | @@ -254,6 +254,27 @@ pub fn spawn(pool: *Pool, comptime func: anytype, args: anytype) !void { |
| 254 | 254 | pool.cond.signal(); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | test spawn { |
| 258 | const TestFn = struct { |
| 259 | fn checkRun(completed: *bool) void { |
| 260 | completed.* = true; |
| 261 | } |
| 262 | }; |
| 263 | |
| 264 | var completed: bool = false; |
| 265 | |
| 266 | { |
| 267 | var pool: Pool = undefined; |
| 268 | try pool.init(.{ |
| 269 | .allocator = std.testing.allocator, |
| 270 | }); |
| 271 | defer pool.deinit(); |
| 272 | try pool.spawn(TestFn.checkRun, .{&completed}); |
| 273 | } |
| 274 | |
| 275 | try std.testing.expectEqual(true, completed); |
| 276 | } |
| 277 | |
| 257 | 278 | fn worker(pool: *Pool) void { |
| 258 | 279 | pool.mutex.lock(); |
| 259 | 280 | defer pool.mutex.unlock(); |