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
fnwasi_thread_start(tid: i32, arg: *Instance) callconv(.c) void {
comptimeassert(!builtin.single_threaded);
__set_stack_pointer(arg.thread.memory.ptr + arg.stack_offset);
__wasm_init_tls(arg.thread.memory.ptr + arg.tls_offset);
@atomicStore(u32, &WasiThreadImpl.tls_thread_id, @intCast(tid), .seq_cst);
// Finished bootstrapping, call user's procedure.arg.call_back(arg.raw_ptr);
switch (arg.thread.state.swap(.completed, .seq_cst)) {
.running => {
// reset the Thread IDasmvolatile (
\\ local.get %[ptr]\\ i32.const 0\\ i32.atomic.store 0
:
: [ptr] "r" (&arg.thread.tid.raw),
);
// Wake the main thread listening to this threadasmvolatile (
\\ local.get %[ptr]\\ i32.const 1 # waiters\\ memory.atomic.notify 0\\ drop # no need to know the waiters
:
: [ptr] "r" (&arg.thread.tid.raw),
);
},
.completed => unreachable,
.detached => {
// restore the original stack pointer so we can free the memory// without having to worry about freeing the stack__set_stack_pointer(arg.original_stack_pointer);
// Ensure a copy so we don't free the allocator reference itselfvarallocator = arg.thread.allocator;
allocator.free(arg.thread.memory);
},
}
}
Called by the host environment after thread creation.