Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upKeeping references to #[thread_local] statics is allowed across yields. #49682
Comments
eddyb
added
I-nominated
A-borrow-checker
T-compiler
I-unsound 💥
A-generators
labels
Apr 5, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
comex
Apr 5, 2018
Contributor
Am I right in assuming the same issue applies to implementations of thread locals in external crates, which aren't limited to unstable? e.g. https://amanieu.github.io/thread_local-rs/thread_local/index.html
edit: I'm wrong. From that page:
Per-thread objects are not destroyed when a thread exits. Instead, objects are only destroyed when the
ThreadLocalcontaining them is destroyed.
Otherwise the API would be blatantly unsound even without generators.
edit2: ignore me; I misunderstood the scope of the problem. For the record, it doesn't apply to thread_local!, or anything else that uses a callback.
|
Am I right in assuming the same issue applies to implementations of thread locals in external crates, which aren't limited to unstable? e.g. https://amanieu.github.io/thread_local-rs/thread_local/index.html edit: I'm wrong. From that page:
Otherwise the API would be blatantly unsound even without generators. edit2: ignore me; I misunderstood the scope of the problem. For the record, it doesn't apply to |
aturon
referenced this issue
Apr 12, 2018
Open
Tracking issue for `thread_local` stabilization #29594
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
triage: P-medium Should fix, not urgent. |
eddyb commentedApr 5, 2018
This does not affect stabilization of
async fnunless#[thread_local]is also stabilizedTry on playground:
Sample output:
You can see by the pointer addresses and values inside
FOOthat the same location was reused for the second child thread (it's a bit harder to show a crash) - this is clearly an use-after-free.If we had in-language
async, the same problem could be demonstrated using those.In non-generator functions, such references have function-local lifetimes and cannot escape.
With the stable
thread_local!fromlibstd, user code gets access to the reference in a (non-generator/async) closure, which also doesn't allow escaping the reference.cc @alexcrichton @withoutboats @Zoxc