Repository navigation
Ensure that tls_destructionMonitor is initialized if a thread is attached to the runtime. - #65358
Conversation
…ched to the runtime.
|
@VSadov most of the runtime tests are failing with the assert in your new code: |
|
I guess that the problem is that we are setting up the destructor during shutdown when we are setting the thread to NULL. We should not be setting up the destructor for that case. |
|
Right, the assert is too strong since threads can detach before terminating. |
jkotas
left a comment
There was a problem hiding this comment.
I think you also want to call EnsureTlsDestructionMonitor only when there is something to cleanup. It is unnecessary and potentially problematic to call it when we are clearing the TLS.
| LIMITED_METHOD_CONTRACT | ||
|
|
||
| gCurrentThreadInfo.m_pThread = t; | ||
| EnsureTlsDestructionMonitor(t); |
There was a problem hiding this comment.
| EnsureTlsDestructionMonitor(t); | |
| if (t != NULL) | |
| EnsureTlsDestructionMonitor(t); |
There was a problem hiding this comment.
With this change, the destructor would need to fetch the thread via GetThreadNULLOk() to make sure we are not touching a thread that is dead (not sure if what we do is safe in such case, we change COOP mode, for example).
That might be a good idea though if we want a minimal change for 6.0 porting purposes.
There was a problem hiding this comment.
~TlsDestructionMonitor calls DetachThread. DetachThread calls SetThread(NULL). I think it would be a good idea to avoid calling EnsureTlsDestructionMonitor from SetThread(NULL) on this path to avoid attempt to re-register object that is being destructed.
There was a problem hiding this comment.
Yes, I just mean we should not rely on storing thread in m_thread and should fetch it via GetThreadNULLOk().
If I use m_thread I get a lot of asserts when switching mode when there is no current thread any more.
| // clean up for us instead). | ||
|
|
||
| Thread* thread = GetThreadNULLOk(); | ||
| Thread* thread = m_thread; |
There was a problem hiding this comment.
Should we delete the ThreadDetach call from DeleteThread and always depend on this path to cleanup the thread?
It would improve the test coverage for the thread cleanup logic - there won't be difference between thread cleanup for threads created by the runtime and threads that wandered into the runtime.
There was a problem hiding this comment.
Should we delete the ThreadDetach call from DeleteThread and always depend on this path to cleanup the thread?
Perhaps in a separate change that we would not port to 6.0 ?
just to manage the risk of regressesing something.
|
|
||
| ~TlsDestructionMonitor() | ||
| { | ||
| // Don't destroy threads here if we're in shutdown (shutdown will |
There was a problem hiding this comment.
This comment does not look relevant. (It was not relevant even before this change.)
|
Thanks!! |
|
/backport to release/6.0 |
|
Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1849767368 |
Fixes:#64509
I have verified that