zigar.thread.WorkQueue(ns).wait(self) - chung-leong/zigar GitHub Wiki
Wait until all threads have started and called ns.onThreadStart()
(if present). Return any error
encountered by any of the threads.
A deadlock will occur if this function is called in the main thread and ns.onThreadStart()
calls
a JavaScript function.
When this function returns an error, a shutdown of the queue will have already occurred.
Usage
const std = @import("std");
const zigar = @import("zigar");
var work_queue: zigar.thread.WorkQueue(ns) = .{};
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
pub fn startup(num_threads: usize) !void {
try work_queue.init(.{
.allocator = allocator,
.n_jobs = num_threads,
.thread_start_params = .{"/tmp/no-where"},
});
try work_queue.wait();
}
const ns = struct {
threadlocal var file: ?std.fs.File = null;
pub fn onThreadStart(path: []const u8) !void {
file = try std.fs.openFileAbsolute(path, .{});
}
};
import { startup } from './work-queue-example-4.zig';
startup(4);
Error: File not found
at startup (<anonymous>:1127:26)
at file:///home/cleong/zigar.wiki/examples/work-queue-example-4.js:3:1 {
number: 55
}
Arguments:
-
self
:@This()
Return value:
void
or ThreadStartError!void