-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[runtime] Wait for the thread to really exit in Thread.Join (). #5454
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.
Other uses are wrapped in MONO_ENTER_GC_SAFE/MONO_EXIT_GC_SAFE. Do we need that here a well?
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.
Will add it.
|
I had to change this slightly to make it work on Windows. The diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c
index 8eb4fe5f24e..935b3860b5b 100644
--- a/mono/metadata/threads.c
+++ b/mono/metadata/threads.c
@@ -1820,7 +1820,7 @@ ves_icall_System_Threading_Thread_Join_internal(MonoThread *this_obj, int ms)
mono_set_pending_exception (mono_get_exception_thread_state ("Thread has not been started."));
return FALSE;
}
-
+ MonoNativeThreadId tid = thread_get_tid (thread);
UNLOCK_THREAD (thread);
if(ms== -1) {
@@ -1839,6 +1839,14 @@ ves_icall_System_Threading_Thread_Join_internal(MonoThread *this_obj, int ms)
if(ret==MONO_THREAD_INFO_WAIT_RET_SUCCESS_0) {
THREAD_DEBUG (g_message ("%s: join successful", __func__));
+ /* Wait for the thread to really exit */
+ MONO_ENTER_GC_SAFE;
+ /* This shouldn't block */
+ mono_threads_join_lock ();
+ mono_native_thread_join (tid);
+ mono_threads_join_unlock ();
+ MONO_EXIT_GC_SAFE;
+
return(TRUE);
} |
|
LGTM |
|
What code clears the tid ? |
|
A couple of tests are failing today with: Thread 1 (Thread 0x20000029c60 (LWP 62357)): Is the setting of thread->tid something that's platform specific? Neale |
|
Its somewhat platform specific, but all unix platforms have the same implementation. |
|
I see the following for the crash and the thread->tid in question:
tid is being set in mono_thread_attach_internal()
Cleared at the end of start_wrapper_internal() (around line 1027)
Used in ves_icall_System_Threading_Thread_Join_internal()
Neale
|
|
Ok, will revert and investigate. |
This is the behavior of .NET. After this patch the code on Mono for Windows will make sure the underlying native thread of a managed thread has died before Thread.Join() returns. This PR builds on PR mono#5454 but makes it Windows specific. PR mono#5454 was reverted since it caused crashes on some Unix platforms.
|
The symptom I reported a couple of weeks has reappeared. It appears the thread exits, the tid is zeroed but it still appears in the hash table. I circumvented the SEGV with: |
|
The commit has been reverted so this problem is not caused by it. |
|
@nealef probably the same issue: #5532 (comment) |
|
@nealef @vargaz @luhenry this might be connected to https://bugzilla.xamarin.com/show_bug.cgi?id=59371 ... I suggest to remove the line that sets |
|
Another try: |
|
@akoeplinger do you think it's interesting/possible/useful to add a Redhat distribution to the CI to capture a few more distro specific issues? |
…). (mono/mono#5454)" This reverts commit mono/mono@ec30afd. It causes test failures on s390x. Commit migrated from mono/mono@c603a69
This is the behavior of .NET. After this patch the code on Mono for Windows will make sure the underlying native thread of a managed thread has died before Thread.Join() returns. This PR builds on PR mono/mono#5454 but makes it Windows specific. PR mono/mono#5454 was reverted since it caused crashes on some Unix platforms. Commit migrated from mono/mono@95f0800
No description provided.