-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[[runtime] Wait for the thread to really exit in Thread.Join (). Chan… #5549
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
Conversation
mono/metadata/threads.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to have a check that does not rely on tid != 0 since, in theory, 0 is a valid thread id on many systems?
|
The test failures are caused by this PR. |
2a97a54 to
a32090c
Compare
|
Where do we stand with this? |
|
It still causes test failures on linux. |
a32090c to
74c3322
Compare
…-in-Thread-Join Wait for the native thread to die in Thread.Join() on Windows
mono/metadata/threads.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, when thread_get_tid() was called here in a previous attempt to fix this issue it occasionally returned 0 on Windows. That is why I had to move the thread_get_tid() call up to the LOCK_THREAD block. Let me know and I can help you test your PR on Windows, just to make sure it works 100% of the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling it earlier is not going to work since the thread might not been started yet, so it doesn't have a tid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that tested for here: https://github.com/vargaz/mono/blob/74c3322958194d74d3d47473230018965fc4409f/mono/metadata/threads.c#L1820? IIUC if the thread is unstarted this condition will trigger and the fuction returns FALSE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that test is racy, since the flag is not cleared in the newly created thread but in the creating thread. Obtaining the tid after the join () call should be better because join () will only return when the thread is close to terminating, which ensures it set its tid field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it return 0 on windows because of:
96ace09
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha, I wasn't aware of 96ace09. That could be why tid sometimes was 0. I will try your PR on the flaky WaitHandleTest on Windows today and let you know. The PR builds don't reliably test for this flakiness since it only happens occasionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have run WaitHandleTest 100 times on Windows x64 without seeing the previous flakiness. So as far as Windows is concerned this PR looks good!
|
Some linux tests are still reliably failing with this PR. |
…ge the check for started threads in mono_thread_set_name_internal () so it check the thread state and not the tid. Avoid setting the tid to 0 when the thread exits.
74c3322 to
2ac4f07
Compare
|
Needed to call mono_thread_join () which actually tests that the thread has not been joined yet. |
kumpera
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
build |
|
This might still be racy, since mono_thread_join () will be a no-op if the thread is not yet added to the joinable threads list, which happens in the sgen unregister callback, much later than the thread event getting signalled. |
|
The linux failures seems to be gone. |
|
build |
|
I still timeout running tests. This is running finalizer-exit with a timeout of 300. |
|
This PR only affects Thread.Join () those failures are probably unrelated. |
|
You are correct, it was a hangover from the thread exit fix that was merged yesterday. I was trying to recreate the problem by lowering the timeout and lowered it too far. Back at the default all tests now pass. Apologies. |
…ge the check for started threads in mono_thread_set_name_internal () so it check the thread state and not the tid. Avoid setting the tid to 0 when the thread exits. (mono/mono#5549) Commit migrated from mono/mono@52b96a9
…ge the check for started threads in mono_thread_set_name_internal () so it check the thread state and not the tid. Avoid setting the tid to 0 when the thread exits.