@@ -128,20 +128,25 @@ TLS bookkeeping (this is not much different than how C starts threads natively).
128
128
### Detailed design discussion
129
129
130
130
Threads are tricky to implement. This proposal relies on a specific WebAssembly
131
- convention in order to work correctly. Upon a call to `wasi_thread_spawn`, the
132
- WASI host must:
131
+ convention in order to work correctly.
132
+
133
+ When instantiating a module which is expected to run with wasi-threads,
134
+ the WASI host must:
135
+
136
+ 1. create and provide shared memories to satisfy the module's imports.
137
+
138
+ Upon a call to `wasi_thread_spawn`, the WASI host must:
139
+
133
140
1. instantiate the module again — this child instance will be used for the
134
141
new thread
135
- 2. in the child instance, ensure that any `shared` memories are the same ones as
136
- those of the parent
137
- 3. in the child instance, import all of the same WebAssembly objects as the
138
- parent
139
- 4. optionally, spawn a new host-level thread (other spawning mechanisms are
142
+ 2. in the child instance, import all of the same WebAssembly objects,
143
+ including the above mentioned shared memories, as the parent
144
+ 3. optionally, spawn a new host-level thread (other spawning mechanisms are
140
145
possible)
141
- 5 . calculate a positive, non-duplicate thread ID, `tid`, and return it to the
146
+ 4 . calculate a positive, non-duplicate thread ID, `tid`, and return it to the
142
147
caller; any error in the previous steps is indicated by returning a negative
143
148
error code.
144
- 6 . in the new thread, call the child instance's exported entry function with the
149
+ 5 . in the new thread, call the child instance's exported entry function with the
145
150
thread ID and the start argument: `wasi_thread_start(tid, start_arg)`
146
151
147
152
A WASI host that implements the above should be able to spawn threads for a
0 commit comments