-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Wait for the native thread to die in Thread.Join() on Windows #5037
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
Closed
ntherning
wants to merge
1
commit into
mono:master
from
ntherning:wait-for-native-thread-to-die-in-Thread-Join-on-windows
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1821,6 +1821,13 @@ ves_icall_System_Threading_Thread_Join_internal(MonoThread *this_obj, int ms) | |
| return FALSE; | ||
| } | ||
|
|
||
| #ifdef HOST_WIN32 | ||
| gboolean is_runtime_thread = FALSE; | ||
| if ((thread->state & (ThreadState_Stopped | ThreadState_Aborted)) == 0) { | ||
| is_runtime_thread = ((MonoThreadInfo*) thread->thread_info)->runtime_thread; | ||
| } | ||
| #endif | ||
|
|
||
| UNLOCK_THREAD (thread); | ||
|
|
||
| if(ms== -1) { | ||
|
|
@@ -1837,6 +1844,13 @@ ves_icall_System_Threading_Thread_Join_internal(MonoThread *this_obj, int ms) | |
| mono_error_set_pending_exception (&error); | ||
|
|
||
| if(ret==MONO_THREAD_INFO_WAIT_RET_SUCCESS_0) { | ||
| #ifdef HOST_WIN32 | ||
| if (is_runtime_thread) { | ||
| // The thread was created by the runtime. Make sure the underlying | ||
| // native thread has terminated before we return. | ||
| WaitForSingleObjectEx (thread->native_handle, INFINITE, FALSE); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong, the WaitOne should respect the timeout of the icall. |
||
| } | ||
| #endif | ||
| THREAD_DEBUG (g_message ("%s: join successful", __func__)); | ||
|
|
||
| return(TRUE); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Doesn't mono_join_uninterrupted () already do this ?
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.
Shouldn't this use the same mechanics as mono_threads_join_threads ?
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.
@vargaz IIUC
mono_join_uninterruptedwaits for an event to be signalled in the other thread (inmono_threads_signal_thread_handlewhich is called byunregister_thread). When the event is signalled the native thread has not yet been fully terminated.@kumpera I guess you mean doing something similar to https://github.com/mono/mono/blob/master/mono/metadata/threads.c#L5048? Is that entire sequence starting with
MONO_ENTER_GC_SAFErequired?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 mean using that very thing, but replacing pthread_join with WaitOne