-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
add #[thread_local]
attribute
#10312
Conversation
Is it possible to test this? Something with |
@huonw: I'm building/testing the runtime ported to it right now, I think that should be adequate if it works :). |
It seems this is at least twice as fast as |
#10315 is open about getting this working on Windows by switching to mingw-w64 |
cc @brson |
Let's wait for further discussion on this. |
What mechanism does LLVM use for TLS that makes it faster than pthread_getspecific? Is it just avoiding a function call, or is it a completely different implementation? |
Why doesn't this work on windows? |
@brson: It will work anywhere with support for C11/C++11 (they have |
So this adds a new runtime dependency on C11, specifically |
@brson: It existed before C11, because there was previously a |
http://www.akkadia.org/drepper/tls.pdf
|
At an assembly level on x86 Linux, this simply compiles to an access in the |
This seems to automatically solve the problem of globally initializing TLS keys, which is nice. I'm pretty concerned about adding a language feature that doesn't work on all platforms though. Also, though I see this has some potential benefits over using platform TLS libraries, I don't want to get in the habit of simply exposing every LLVM feature through Rust just because it's easy. Hopefully others will offer opinions about this. |
From what I could tell, it looked like LLVM pretty much fully supported this on all platforms that LLVM supports. We'll never be able to support a platform that LLVM doesn't, so my own worries about this not necessarily working everywhere were alleviated after learning this. I personally really like this because it solves the static initialization problem, and primarily for that reason. I suppose that this could get a little weird if you're using I'm still a little wary of this not being supported on windows yet. We're not only exporting this for the runtime, but also for the language as a whole. I don't think that we quite have a roadmap for migrating to mingw64 soon, so I'm not sure that we should commit to this until we have a plan for getting this to work on windows as well. I believe that this is a lot faster than the current scheme, but I'm not entirely convinced that it's necessary to speed up these lookups. If it is the case that we see a huge improvement in runtime-related benchmark, then there may be more of an impetus for this, and perhaps in that situation we shouldn't have a |
I think this does work on every platform we'd potentially want to support (x86, x86_64, x32, ARM, SPARC, AArch64, SystemZ, MIPS, PowerPC, etc.) and it does work on Windows with either MSVC++ or MinGW-w64. Our floating point support is broken on Windows due to MinGW too (#8663, #8755). I don't really see another way to have solid support for thread-local data in freestanding Rust. If it can speed up task-local data in libstd, that's a bonus. |
@alexcrichton: It completely works in a statically linked executable. It's just much faster without dynamic linking because it's only a normal memory access via a pointer rather than a linker feature. |
I've added this to the minutes of the next meeting. |
If it's decided that this isn't wanted, it would be nice if it could still be added behind a feature flag because I need it for rust-core's threading API. |
I think this is useful. GCC has had this for quite some time. We can warn/error if ever we port to a platform this isn't supported on. Or, just add support to LLVM. |
@cmr: as a standard C11/C++11 feature I think it will be more portable than Rust (it's just than MinGW is awful, MinGW-w64 on the other hand has this fully working) |
I am fine with this. I'll bring it up at the meeting. |
We decided today that we should add this, but usage of the attribute should be a feature-gate. Would you mind adding a feature gate for this as well (may involve a stage0 dance) |
This provides a building block for fast thread-local storage. It does not change the safety semantics of `static mut`. Closes #10310
This provides a building block for fast thread-local storage. It does not change the safety semantics of `static mut`. Closes #10310
This provides a building block for fast thread-local storage. It does
not change the safety semantics of
static mut
.Closes #10310