Skip to content
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 and Finalization/GC #101839

Open
benaadams opened this issue May 3, 2024 · 4 comments
Open

ThreadLocals and Finalization/GC #101839

benaadams opened this issue May 3, 2024 · 4 comments
Labels
area-VM-coreclr untriaged New issue has not been triaged by the area owner

Comments

@benaadams
Copy link
Member

When a thread exits; all its thread locals end up on the finalization queue (perhaps unsurprisingly)

However the runtime is controling when threads are exited; would it be possible it instead dispose all these locals as part of the thread exit so they don't all end up on the finalization queue?

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 3, 2024
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/gc
See info in area-owners.md if you want to be subscribed.

@KalleOlaviNiemitalo
Copy link

KalleOlaviNiemitalo commented May 3, 2024

The thread-local field might not be the only thing that refers to the same instance. In that case, it would be wrong to automatically dispose or finalize the referenced instance when the thread exits, unless the thread-local field is opted in somehow. (Perhaps a new bool DisposeValueOnThreadExit property on ThreadStaticAttribute and ThreadLocal<T>; the IDisposable.Dispose implementation could then call GC.SuppressFinalize.)

Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-VM-coreclr untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

4 participants