-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Keeping references to #[thread_local] statics is allowed across yields. #49682
Copy link
Copy link
Open
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-coroutinesArea: CoroutinesArea: CoroutinesC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-coroutines`#![feature(coroutines)]``#![feature(coroutines)]`F-thread_local`#![feature(thread_local)]``#![feature(thread_local)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityMedium priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-coroutinesArea: CoroutinesArea: CoroutinesC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-coroutines`#![feature(coroutines)]``#![feature(coroutines)]`F-thread_local`#![feature(thread_local)]``#![feature(thread_local)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-mediumMedium priorityMedium priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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