Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions mono/metadata/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Copy link
Contributor

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 ?

Copy link
Contributor

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 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vargaz IIUC mono_join_uninterrupted waits for an event to be signalled in the other thread (in mono_threads_signal_thread_handle which is called by unregister_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_SAFE required?

Copy link
Contributor

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

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);
Copy link
Contributor

@kumpera kumpera Aug 23, 2017

Choose a reason for hiding this comment

The 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);
Expand Down