This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function
fnstart(r: *Runnable, thread: *Thread, t: *Threaded) void {
consttask: *Task = @fieldParentPtr("runnable", r);
constgroup: Group = .{ .ptr = task.group };
// This would be a simple store, but it's upgraded to an RMW so we can use `.acquire` to// enforce the ordering between this and the `group.status().load` below. Paired with// the `.release` rmw on `Thread.status` in `cancelThreads`, this creates a StoreLoad// barrier which guarantees that when a group is canceled, either we see the cancelation// in the group status, or the canceler sees our thread status so can directly notify us// of the cancelation._ = thread.status.swap(.{
.cancelation = .none,
.awaitable = .fromGroup(group.ptr),
}, .acquire);
if (group.status().load(.monotonic).canceled) {
thread.status.store(.{
.cancelation = .canceling,
.awaitable = .fromGroup(group.ptr),
}, .monotonic);
}
task.func(task.contextPointer());
thread.status.store(.{ .cancelation = .none, .awaitable = .null }, .monotonic);
constold_status = group.status().fetchSub(.{
.num_running = 1,
.have_awaiter = false,
.canceled = false,
}, .acq_rel); // acquire `group.awaiter()`, release task resultsassert(old_status.num_running > 0);
if (old_status.have_awaiterandold_status.num_running == 1) {
constto_signal = group.awaiter().*;
// `awaiter` should only be modified by us. For another thread to see `num_running`// drop to 0 after this point would indicate that another task started up, meaning// `async`/`cancel` was racing with awaited group completion.group.awaiter().* = undefined;
_ = to_signal.fetchAdd(1, .release); // release resultsThread.futexWake(&to_signal.raw, 1);
}
// Task completed. Self-destruct sequence initiated.task.destroy(t.allocator);
}