Implement WebAssembly thread-local support for WASIX #3699
Labels
🎉 enhancement
New feature!
📦 lib-wasi
About wasmer-wasi
lib-wasix
Issues related to the WASIX toolchain.
priority-medium
Medium priority issue
Milestone
Goal
Currently
wasix
uses syscalls for getting and setting local thread variables which adds quite some overhead - instead the TLS area should be used for this thus avoiding this overhead and removing some redundant syscalls.Impacted syscalls
The syscalls impacted are as follows:
Rust Standard Library
The rust standard library must be modified in order to use TLS instead of the
wasix
syscalls - the locations of the thread local implementation is as follows:https://github.com/wasmerio/rust/blob/wasix/library/std/src/thread/local.rs
https://github.com/wasmerio/rust/blob/wasix/library/std/src/sys/wasix/atomics/thread_local_key.rs
Avoiding memory leaks
Particular attention must be made that when threads exit they do not cause memory leaks, at present this is done by creating a callback that the runtime executes after the thread exits
_thread_local_destroy
. This method will free any memory used by the local thread variables including invoking any destructors (for unsafe allocations). One could use thepthreads
libc implementation to achieve the same thing rather than having this as a runtime responsibility.wasix-libc
Threading is currently implemented using
pthreads
in the libc fork here:https://github.com/wasmerio/wasix-libc
One approach to solving this problem would be to implement rust local thread storage entirely using the pthreads implementation however this is not the only way approach and a fully rust native solution is also possible.
Cargo build
WASIX applications can be compiled using this helpful toolchain fork:
https://github.com/wasmerio/cargo-wasix
Testing
There is a fully working http server that uses local thread storage extensively and thus can be used for functional and non-functional tests - it is located here:
https://github.com/john-sharratt/static-web-server
The text was updated successfully, but these errors were encountered: