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? 🤔
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.