I’ve been doing some research around supporting wa...
# webassembly
c
I’ve been doing some research around supporting wasm targets for my KPM library, for now I’m focusing on wasm-js. I use ThreadLocals in my library algorithm but given threading hasn’t yet been fully standardised yet I take it that this is out of the question? Looking at the proposal threads will simply mark a portion of the wasm modules memory as “shared” and use atomics to support safe thread communication. Would TLS simply equate to another area of non shared linear memory for the module? I’m using this is what emscripten does? For the moment its largely unimportant given its single threaded but it would be good to write an implementation that is future proof. With that in mind is there a way to malloc, or maybe I could hack something using globals? 🤔
e
in the future, it might become possible to share objects across threads, but there is no proposed design for it yet https://github.com/WebAssembly/reference-types/issues/26
s
Current threads proposal that works with shared linear memory is not applicable to Kotlin because it allocates memory in a separate, currently non-shared, GC heap. There is a new proposal for making everything shared: https://github.com/WebAssembly/shared-everything-threads. Design is at the very early stage, but it has ideas about TLS. I hope that when this is ready, we will be able to express TLS in Kotlin/Wasm in the same way it will be done in the rest of KMP.
👍 1
e
just to make things more complex, there is also a separate https://github.com/WebAssembly/wasi-threads in the works
or was, I guess? I don't see recent activity on it
I'd seen the first threads proposal but not the shared-everything one. that looks like it would work much better for kotlin/wasm
s
These overlap in thread creation. See this discussion. We will still need the “sharing” parts