-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Runtime: emulate TLS with a map for WASI target #31694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Why cant you use |
CC: @mikeash |
I didn't know about |
static inline int _stdlib_thread_key_create(__swift_thread_key_t *key, | ||
__swift_thread_key_destructor destructor) { | ||
if (!_stdlib_tls_map) | ||
_stdlib_tls_map = new _stdlib_tls_map_t(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_stdlib_tls_map = new _stdlib_tls_map_t(); | |
_stdlib_tls_map = new _stdlib_tls_map_t(); |
Nit: if still pursuing this PR, would you mind running the changes through the clang-format tool?
@compnerd I had another look at |
I think the best long-term plan would be to add a mode to ThreadLocalStorage.cpp that can use a thread-local variable, like we have in Exclusivity.cpp. I'm not sure why we only have that in one of those files, maybe they just evolved separately. That would allow you to use |
Using |
Sorry to revive this, but is TLS still an issue with built-in concurrency? |
The runtime still needs thread-local storage for various things even if application code is using higher-level constructs. For example, retrieving a task-local variable in user code works by using TLS to fetch the current task running on the current thread, then retrieving the thread-local variable from that task. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The map access needs locking, which I believe is missing or am I misreading the patch?
Can we get away with just using -femul-tls when building for WASI? That should let us use a tested implementation for the mapping from compiler-Ty.
Closing in favor of cleaner |
Runtime thread-local storage has to be emulated for WebAssembly/WASI as WebAssembly currently doesn't support threads.
Related to SR-9307.
(cc @compnerd @kateinoigakukun)