Fix thread pool completed work item counter to remove finalized nodes (#57305)
authorKoundinya Veluri <kouvel@users.noreply.github.com>
Sat, 14 Aug 2021 04:52:46 +0000 (21:52 -0700)
committerGitHub <noreply@github.com>
Sat, 14 Aug 2021 04:52:46 +0000 (22:52 -0600)
commit30a2709528ce52c9576513c43d5370def593171b
tree0ad3ee19a656e0d72df89febde5b4728583f5034
parent6652d4ebca2ef1beae1c8eb94dad58662d987d47
Fix thread pool completed work item counter to remove finalized nodes (#57305)

* Fix thread pool completed work item counter to remove finalized nodes

- New nodes are being added to the set but finalized ones were not being removed
- This would result in double-counting the completed work item count for a thread that exits, and memory would grow over time

* Add a separate finalization helper for each node to track thread-local lifetimes

* Remove unnecessary IDisposable

* Fix nullability issues

* Update initialization of thread-local as suggested

Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
src/libraries/System.Private.CoreLib/src/System/Threading/ThreadInt64PersistentCounter.cs