From 5e248d825385ac3bcd36f162262c68d6cf448e85 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Sat, 24 Dec 2022 11:59:36 +0900 Subject: [PATCH] Clarify how shared memories are created and shared --- README.md | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 73ea43b..2f46e7d 100644 --- a/README.md +++ b/README.md @@ -128,20 +128,25 @@ TLS bookkeeping (this is not much different than how C starts threads natively). ### Detailed design discussion Threads are tricky to implement. This proposal relies on a specific WebAssembly -convention in order to work correctly. Upon a call to `wasi_thread_spawn`, the -WASI host must: +convention in order to work correctly. + +When instantiating a module which is expected to run with wasi-threads, +the WASI host must: + +1. create and provide shared memories to satisfy the module's imports. + +Upon a call to `wasi_thread_spawn`, the WASI host must: + 1. instantiate the module again — this child instance will be used for the new thread -2. in the child instance, ensure that any `shared` memories are the same ones as - those of the parent -3. in the child instance, import all of the same WebAssembly objects as the - parent -4. optionally, spawn a new host-level thread (other spawning mechanisms are +2. in the child instance, import all of the same WebAssembly objects, + including the above mentioned shared memories, as the parent +3. optionally, spawn a new host-level thread (other spawning mechanisms are possible) -5. calculate a positive, non-duplicate thread ID, `tid`, and return it to the +4. calculate a positive, non-duplicate thread ID, `tid`, and return it to the caller; any error in the previous steps is indicated by returning a negative error code. -6. in the new thread, call the child instance's exported entry function with the +5. in the new thread, call the child instance's exported entry function with the thread ID and the start argument: `wasi_thread_start(tid, start_arg)` A WASI host that implements the above should be able to spawn threads for a