# std: implement \`Thread\` \`spawn\` for WASI · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/a97dbdfa0b1246913ba90cd5c05ff633e9003cb9)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: a97dbdfa0b1246913ba90cd5c05ff633e9003cb9

Requested commit: a97dbdfa0b1246913ba90cd5c05ff633e9003cb9

Commit: a97dbdfa0b1246913ba90cd5c05ff633e9003cb9

Tree: 39b0d61f4c6ee95e6d3ba39a9ce91c676398c929

Author: Luuk de Gram

Committer: Luuk de Gram

## Message

```
std: implement `Thread` `spawn` for WASI

This implements a first version to spawn a WASI-thread. For a new thread
to be created, we calculate the size required to store TLS, the new stack,
and metadata. This size is then allocated using a user-provided allocator.

After a new thread is spawn, the HOST will call into our bootstrap procedure.
This bootstrap procedure will then initialize the TLS segment and set the
newly spawned thread's TID. It will also set the stack pointer to the newly
created stack to ensure we do not clobber the main thread's stack.

When bootstrapping the thread is completed, we will call the user's
function on this new thread.

```

## Parents

- [ea0d4c8377aeabe1ef588e82cbdd9aa729adbce0](https://git.cafe/gitcafe/zig/commit/ea0d4c8377aeabe1ef588e82cbdd9aa729adbce0?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/a97dbdfa0b1246913ba90cd5c05ff633e9003cb9?format=markdown)
