4d3cffa3cf
Currently the compiler has no knowledge of `#[thread_local]` which forces users to take on two burdens of unsafety: * The lifetime of the borrow of a `#[thread_local]` static is **not** `'static` * Types in `static`s are required to be `Sync` The thread-local modules mostly curb these facets of unsafety by only allowing very limited scopes of borrows as well as allowing all types to be stored in a thread-local key (regardless of whether they are `Sync`) through an `unsafe impl`. Unfortunately these measures have the consequence of being able to take the address of the key itself and send it to another thread, allowing the same key to be accessed from two different threads. This is clearly unsafe, and this commit fixes this problem with the same trick used by `LocalKey`, which is to have an indirect function call to find the address of the *current thread's* thread local. This way the address of thread local keys can safely be sent among threads as their lifetime truly is `'static`. This commit will reduce the performance of cross-crate scoped thread locals as it now requires an indirect function call, but this can likely be overcome in a future commit. Closes #25894 |
||
---|---|---|
.. | ||
collections | ||
ffi | ||
io | ||
net | ||
num | ||
os | ||
prelude | ||
rand | ||
rt | ||
sync | ||
sys | ||
thread | ||
time | ||
array.rs | ||
ascii.rs | ||
bool.rs | ||
dynamic_lib.rs | ||
env.rs | ||
error.rs | ||
fs.rs | ||
lib.rs | ||
macros.rs | ||
panicking.rs | ||
path.rs | ||
process.rs | ||
rtdeps.rs | ||
thunk.rs | ||
tuple.rs | ||
unit.rs |