Skip to content

Use WIT's result<> type for thread-spawn's return values #29

Description

@loganek

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions