Description
Because thread-spawn
can fail, we use return value to communicate error code. We also use return value to communicate success and pass thread id to the user. This usecase nicely fits into variant type, and more specifically - result<>
. It also feels like an idiomatic way of handling this kind of usecase in WIT.
I propose we update the type of thread-spawn
to be:
type thread-id = u32
start-arg
result<thread-id, errno>
where thread-id
is a non-negative integer (type start-arg = u32
) and errno
is an enum representing all potential errors returned by thread-spawn
.
Please note that the consequence of this change is updated C interface:
void __wasi_thread_spawn(int32_t, int32_t);
where the second parameter is a pointer to a memory dedicated for the return value.
I'm seeking for feedback/suggestions; once we have a high-level agreement, the next steps are:
[ ] define (initial) set of error codes
[ ] update proposal and WIT definition (#28)
[ ] update toolchains (wasi-libc, ...?)
[ ] update runtimes that already implemented the proposal or have the work in-progress (wasmtime, WAMR, ...?)
See also: #26