Skip to content

Commit 7ef423a

Browse files
authored
[thread-spawn] Fix TLS discussion (#9)
1 parent dfeb20e commit 7ef423a

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

proposals/thread-spawn/Overview.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ paper for the sequential consistency guarantees). Following the paper, this prop
149149

150150
- `shared` tables will be grown and modified atomically
151151
- `shared` globals will be modified atomically
152-
- `shared` functions can only call other `shared` functions; any non-`shared` objects are
153-
thread-local
152+
- `shared` functions can never access non-`shared` objects; e.g., they only call other `shared`
153+
functions and only access `shared` memories, tables, and globals
154154

155155
__TODO__: add a WAT example
156156

@@ -213,12 +213,16 @@ This issue can be discussed further here: [Should we include
213213

214214
### What about thread-local storage (TLS)?
215215

216-
`shared` attributes partition the module's objects into two sets: `shared` and thread-local. Each
217-
object (table, memory, global) that is not shared is initialized with its default values (e.g., a
218-
memory has `data` entries) and any changes are only visible to the thread itself. These non-`shared`
219-
objects can be used for thread-local storage. Alternately, one could use a specific section of
220-
shared memory for TLS, as [wasi-libc][wasi-libc-tls] currently does for C's auxiliary stack.
216+
`shared` attributes prevent `shared` functions from accessing any non-`shared` objects. This means
217+
that TLS must be implemented by indexing a thread (see [TIDs]) into something `shared`, e.g., a
218+
`shared` memory.
221219

220+
One might imagine splitting up tables or sets of globals for TLS, but `shared` memories are likely
221+
more straightforward. For example, when compiling C/C++ to WebAssembly, address-taken local
222+
variables are placed on an auxiliary stack in linear memory. For wasi-threads support, wasi-libc was
223+
already modified [to understand][wasi-libc-tls] how to manage thread-local versions of this stack.
224+
225+
[TIDs]: #what-about-thread-ids-tids
222226
[wasi-libc-tls]: https://github.com/WebAssembly/wasi-libc/blob/bd950eb128bff337153de217b11270f948d04bb4/libc-top-half/musl/src/thread/pthread_create.c#L456
223227

224228
__TODO__: how is this different than a new instance?
@@ -251,7 +255,7 @@ implemented via the existing `wait` and `notify` instructions.
251255

252256
### What about exiting a thread?
253257

254-
There are a couple of sides to this; recall that that "thread" here means a function invoked via
258+
There are a couple of sides to this; recall that "thread" here means a function invoked via
255259
`thread.spawn`:
256260

257261
1. If a thread is __finished__ (e.g., `return`), it simply ends. There is no caller to return to and

0 commit comments

Comments
 (0)