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

Skip to content
Merged
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
27 changes: 11 additions & 16 deletions mono/metadata/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ static guint32 WINAPI start_wrapper_internal(StartInfo *start_info, gsize *stack

mono_thread_detach_internal (internal);

return(0);
return 0;
}

static gsize WINAPI
Expand Down Expand Up @@ -1591,6 +1591,8 @@ ves_icall_System_Threading_Thread_GetName_internal (MonoInternalThread *this_obj
void
mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, gboolean permanent, gboolean reset, MonoError *error)
{
MonoNativeThreadId tid = 0;

LOCK_THREAD (this_obj);

error_init (error);
Expand All @@ -1617,14 +1619,16 @@ mono_thread_set_name_internal (MonoInternalThread *this_obj, MonoString *name, g
else
this_obj->name = NULL;


if (!(this_obj->state & ThreadState_Stopped))
tid = thread_get_tid (this_obj);

UNLOCK_THREAD (this_obj);

if (this_obj->name && this_obj->tid) {
if (this_obj->name && tid) {
Copy link
Contributor

@cherusker cherusker Sep 12, 2017

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?

char *tname = mono_string_to_utf8_checked (name, error);
return_if_nok (error);
MONO_PROFILER_RAISE (thread_name, (this_obj->tid, tname));
mono_native_thread_set_name (thread_get_tid (this_obj), tname);
MONO_PROFILER_RAISE (thread_name, ((uintptr_t)tid, tname));
mono_native_thread_set_name (tid, tname);
mono_free (tname);
}
}
Expand Down Expand Up @@ -1820,8 +1824,6 @@ ves_icall_System_Threading_Thread_Join_internal (MonoThread *this_obj, int ms)
return FALSE;
}

MonoNativeThreadId tid = thread_get_tid (thread);

UNLOCK_THREAD (thread);

if (ms == -1)
Expand All @@ -1839,16 +1841,9 @@ 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__));

#ifdef HOST_WIN32
/* TODO: Do this on Unix platforms as well. See PR #5454 for context. */
/* 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;
#endif
MonoNativeThreadId tid = thread_get_tid (thread);
mono_thread_join (tid);

return TRUE;
}
Expand Down