Uh oh!
There was an error while loading. Please reload this page.
fix weak memory bug in TLS on Windows - #124281
Conversation
rustbot
commented
Apr 23, 2024
r? @ChrisDenton rustbot has assigned @ChrisDenton. Use |
Ah yes, this is clearly a bug.
There was: the destructor may be called as soon as it is registered so I wanted to make sure that the key was set at that point, as You can fix this by skipping the TLS variable in |
RalfJung
commented
Apr 23, 2024
Ah, makes sense. And in the Miri testcase, we don't have a thread-exit racing with a key-init so we wouldn't hit this. I have updated the code. |
Uh oh!
There was an error while loading. Please reload this page.
RalfJung
commented
Apr 23, 2024
I extended the Miri test to also cover this, that triggered the bug immediately: //! Regression test for <https://github.com/rust-lang/rust/issues/123583>.use std::thread;fnwith_thread_local1(){thread_local!{staticX:Box<u8> = Box::new(0);}X.with(|_x| {})}fnwith_thread_local2(){thread_local!{staticY:Box<u8> = Box::new(0);}Y.with(|_y| {})}fnmain(){// Here we have two threads racing on initializing the thread-local// and (on Windows without target_thread_local) adding it to the global dtor list.let t = thread::spawn(with_thread_local1);with_thread_local1();
t.join().unwrap();// Here we have one thread running the destructors racing with another thread initializing a thread-local.// The second thread adds a destructor that could be picked up by the first thread.let t = thread::spawn(|| {/* immediately just run destructors */});with_thread_local2();// initialize thread-local
t.join().unwrap();} |
joboet
commented
Apr 24, 2024
Thank you very much, especially for the detailed comments! |
bors
commented
Apr 24, 2024
RalfJung
commented
Apr 24, 2024
The regression tests are being added on the Miri side in rust-lang/miri#3501. |
Rollup of 6 pull requests Successful merges: - rust-lang#123316 (Test `#[unix_sigpipe = "inherit"]` with both `SIG_DFL` and `SIG_IGN`) - rust-lang#123794 (More DefineOpaqueTypes::Yes) - rust-lang#123881 (Bump Fuchsia versions) - rust-lang#124281 (fix weak memory bug in TLS on Windows) - rust-lang#124282 (windows fill_utf16_buf: explain the expected return value) - rust-lang#124308 (Add diagnostic item for `std::iter::Enumerate`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 6 pull requests Successful merges: - rust-lang#123316 (Test `#[unix_sigpipe = "inherit"]` with both `SIG_DFL` and `SIG_IGN`) - rust-lang#123794 (More DefineOpaqueTypes::Yes) - rust-lang#123881 (Bump Fuchsia versions) - rust-lang#124281 (fix weak memory bug in TLS on Windows) - rust-lang#124282 (windows fill_utf16_buf: explain the expected return value) - rust-lang#124308 (Add diagnostic item for `std::iter::Enumerate`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#124281 - RalfJung:win-tls, r=joboet fix weak memory bug in TLS on Windows We need to store the `key` *after* we register the dtor. Now I hope there isn't also some other reason why we have to actually register the dtor last... `@joboet` is there a reason you picked this particular order in rust-lang#102655? Fixesrust-lang#123583
We need to store the
keyafter we register the dtor.Now I hope there isn't also some other reason why we have to actually register the dtor last... @joboet is there a reason you picked this particular order in #102655?
Fixes#123583