-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
ThreadLocals of the same type T can interfere with each other's trackAllValues #55796
Comments
Tagging subscribers to this area: @mangod9 Issue DetailsRepro: Problem 1: Problem 2:
|
Why would the expected result be 0? The purpose of trackAllValues:true is that all values are kept, regardless of whether the thread is still alive. Or, at least, that was the intention, even if the docs are confusing on the topic. The idea was to be able to use it for things like parallel aggregations or parallel storage of resources that should be cleaned up; the main host would spawn all of the operations, they'd all go off and do their work on whatever threads, and then the host could query Values after the fact and collect/dispose of all of the values or resources, without concern for whether the underlying threads were still around. So, the actual result of 100 is what I'd expect.
This, however, does appear to be a bug. |
Yes, the docs are confusing. It is not what I would expect the behavior to be by reading the docs. |
Agreed. I'll submit a PR to fix them. |
- Before this change the trackAllValues behavior for ThreadLocal<SomeParticularType> was defined by the first instance of thread local to have its value set on the thread - This could lead to unpredictable memory leaks (where the value was improperly tracked even though it wasn't supposed to be) This reproduces as a memory leak with no other observable behavior - Or data loss, where the Values collection was missing entries. - Change the model so that ThreadLocal<T> trackAllValues behavior is properly defined by the exact ThreadLocal<T> instance in use - Implement by keeping track of the track all changes behavior within the IdManager Fixes dotnet#55796
- Before this change the trackAllValues behavior for ThreadLocal<SomeParticularType> was defined by the first instance of thread local to have its value set on the thread - This could lead to unpredictable memory leaks (where the value was improperly tracked even though it wasn't supposed to be) This reproduces as a memory leak with no other observable behavior - Or data loss, where the Values collection was missing entries. - Change the model so that ThreadLocal<T> trackAllValues behavior is properly defined by the exact ThreadLocal<T> instance in use - Implement by keeping track of the track all changes behavior within the IdManager Fixes #55796
Repro:
Problem 1:
Compile and run the program below
Actual result: 100
Expected result: 0. The values associated with collected threads should not be reported.
Problem 2:
Uncomment
UNRELATED_THREAD_LOCAL
, compile and run the program belowActual result: 0
Expected result: same as with
UNRELATED_THREAD_LOCAL
commented out. The two unrelated ThreadLocal instances should not influence each otherThe text was updated successfully, but these errors were encountered: