]> git.proxmox.com Git - wasi-libc.git/commit
threads: implement `pthread_create` (#325)
authorAndrew Brown <andrew.brown@intel.com>
Tue, 4 Oct 2022 14:21:18 +0000 (07:21 -0700)
committerGitHub <noreply@github.com>
Tue, 4 Oct 2022 14:21:18 +0000 (07:21 -0700)
commit241060c3427c2cdd63aa1e0f7a804ab3f75a413f
treeaf94ee8ea2ef5c629ac668f156c58987285f08c2
parentf2a618feb2a109cb0547aa6a223b67f449ea1c4c
threads: implement `pthread_create` (#325)

* threads: implement `pthread_create`

As described in the [`wasi-threads`] proposal, this change implements
`pthread_create` using the new `wasi_thread_spawn(void *arg)` API. As
described there, `wasi-libc` exports the thread entry point with the
expected name, `wasi_thread_start`, and then unwraps the passed argument
`struct` to invoke the user function with the user argument `struct`.

[`wasi-threads`]: https://github.com/WebAssembly/wasi-threads/pull/5

Previously, the TID was only passed to the child thread entry point; the
parent thread was forced to wait until the child thread set the TID in
the pthread structure. With this change, the TID will be passed not only
to the child thread but also returned to the parent thread, so that
either side can make progress. The `i32.store` becomes an
`i32.atomic.store` to avoid concurrent writes.
Makefile
expected/wasm32-wasi/posix/defined-symbols.txt
expected/wasm32-wasi/posix/undefined-symbols.txt
libc-bottom-half/headers/public/wasi/api.h
libc-bottom-half/sources/__wasilibc_real.c
libc-top-half/musl/src/thread/pthread_create.c