From f4d9546f3c7fda64c767e0966be69b2da4ca8d37 Mon Sep 17 00:00:00 2001 From: Ludovic Henry Date: Wed, 7 Sep 2016 14:28:46 +0200 Subject: [PATCH] [threads] Remove CREATE_SUSPENDED (#3529) * [threads] Remove use of CREATE_SUSPENDED for domain unload thread * [threads] Remove use of CREATE_SUSPENDED for managed thread * [threads] Remove CREATE_SUSPENDED --- mono/io-layer/processes.h | 1 - mono/metadata/appdomain.c | 3 +-- mono/metadata/threads.c | 24 ++++++++++++++++++------ mono/utils/mono-threads.c | 23 ----------------------- mono/utils/mono-threads.h | 5 ----- 5 files changed, 19 insertions(+), 37 deletions(-) diff --git a/mono/io-layer/processes.h b/mono/io-layer/processes.h index 3193bc58731..c4da3eceee1 100644 --- a/mono/io-layer/processes.h +++ b/mono/io-layer/processes.h @@ -130,7 +130,6 @@ struct _WapiShellExecuteInfo #define DEBUG_PROCESS 0x00000001 #define DEBUG_ONLY_THIS_PROCESS 0x00000002 -#define CREATE_SUSPENDED 0x00000004 #define DETACHED_PROCESS 0x00000008 #define CREATE_NEW_CONSOLE 0x00000010 #define NORMAL_PRIORITY_CLASS 0x00000020 diff --git a/mono/metadata/appdomain.c b/mono/metadata/appdomain.c index bc214cc92e2..38f4569430b 100644 --- a/mono/metadata/appdomain.c +++ b/mono/metadata/appdomain.c @@ -2589,11 +2589,10 @@ mono_domain_try_unload (MonoDomain *domain, MonoObject **exc) */ tp.priority = MONO_THREAD_PRIORITY_NORMAL; tp.stack_size = 0; - tp.creation_flags = CREATE_SUSPENDED; + tp.creation_flags = 0; thread_handle = mono_threads_create_thread (unload_thread_main, thread_data, &tp, &tid); if (thread_handle == NULL) return; - mono_thread_info_resume (tid); /* Wait for the thread */ while (!thread_data->done && guarded_wait (thread_handle, INFINITE, TRUE) == WAIT_IO_COMPLETION) { diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index e76f38a473f..239d6ffb899 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -89,6 +89,7 @@ typedef struct MonoThread *obj; MonoObject *delegate; void *start_arg; + MonoCoopSem registered; } StartInfo; typedef union { @@ -662,9 +663,15 @@ static guint32 WINAPI start_wrapper_internal(void *data) * We don't create a local to hold start_info->obj, so hopefully it won't get pinned during a * GC stack walk. */ - MonoInternalThread *internal = start_info->obj->internal_thread; - MonoObject *start_delegate = start_info->delegate; - MonoDomain *domain = start_info->obj->obj.vtable->domain; + MonoInternalThread *internal; + MonoObject *start_delegate; + MonoDomain *domain; + + mono_coop_sem_wait (&start_info->registered, MONO_SEM_FLAGS_NONE); + + internal = start_info->obj->internal_thread; + start_delegate = start_info->delegate; + domain = start_info->obj->obj.vtable->domain; THREAD_DEBUG (g_message ("%s: (%"G_GSIZE_FORMAT") Start wrapper", __func__, mono_native_thread_id_get ())); @@ -860,6 +867,8 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star mono_coop_sem_init (internal->start_notify, 0); internal->start_notify_refcount = 2; + mono_coop_sem_init (&start_info->registered, 0); + if (stack_size == 0) stack_size = default_stacksize_for_thread (internal); @@ -868,7 +877,7 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star */ tp.priority = thread->priority; tp.stack_size = stack_size; - tp.creation_flags = CREATE_SUSPENDED; + tp.creation_flags = 0; thread_handle = mono_threads_create_thread (start_wrapper, start_info, &tp, &tid); @@ -877,6 +886,7 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star mono_threads_lock (); mono_g_hash_table_remove (threads_starting_up, thread); mono_threads_unlock (); + mono_coop_sem_destroy (&start_info->registered); g_free (start_info); mono_error_set_execution_engine (error, "Couldn't create thread. Error 0x%x", GetLastError()); return FALSE; @@ -896,10 +906,12 @@ create_thread (MonoThread *thread, MonoInternalThread *internal, StartInfo *star * launched, to avoid the main thread deadlocking while trying * to clean up a thread that will never be signalled. */ - if (!handle_store (thread, FALSE)) + if (!handle_store (thread, FALSE)) { + mono_coop_sem_destroy (&start_info->registered); return FALSE; + } - mono_thread_info_resume (tid); + mono_coop_sem_post (&start_info->registered); /* * Wait for the thread to set up its TLS data etc, so diff --git a/mono/utils/mono-threads.c b/mono/utils/mono-threads.c index a75adc4599f..22eea19051c 100644 --- a/mono/utils/mono-threads.c +++ b/mono/utils/mono-threads.c @@ -766,12 +766,6 @@ static gboolean mono_thread_info_core_resume (MonoThreadInfo *info) { gboolean res = FALSE; - if (info->create_suspended) { - /* Have to special case this, as the normal suspend/resume pair are racy, they don't work if he resume is received before the suspend */ - info->create_suspended = FALSE; - mono_coop_sem_post (&info->create_suspended_sem); - return TRUE; - } switch (mono_threads_transition_request_resume (info)) { case ResumeError: @@ -1142,7 +1136,6 @@ typedef struct { gint32 ref; MonoThreadStart start_routine; gpointer start_routine_arg; - gboolean create_suspended; gint32 priority; MonoCoopSem registered; MonoThreadInfo *info; @@ -1156,10 +1149,8 @@ inner_start_thread (gpointer data) MonoThreadStart start_routine; gpointer start_routine_arg; guint32 start_routine_res; - gboolean create_suspended; gint32 priority; gsize dummy; - gint res; thread_data = (CreateThreadData*) data; g_assert (thread_data); @@ -1167,7 +1158,6 @@ inner_start_thread (gpointer data) start_routine = thread_data->start_routine; start_routine_arg = thread_data->start_routine_arg; - create_suspended = thread_data->create_suspended; priority = thread_data->priority; info = mono_thread_info_attach (&dummy); @@ -1175,11 +1165,6 @@ inner_start_thread (gpointer data) mono_threads_platform_set_priority (info, priority); - if (create_suspended) { - info->create_suspended = TRUE; - mono_coop_sem_init (&info->create_suspended_sem, 0); - } - thread_data->info = info; mono_coop_sem_post (&thread_data->registered); @@ -1192,13 +1177,6 @@ inner_start_thread (gpointer data) /* thread_data is not valid anymore */ thread_data = NULL; - if (create_suspended) { - res = mono_coop_sem_wait (&info->create_suspended_sem, MONO_SEM_FLAGS_NONE); - g_assert (res == 0); - - mono_coop_sem_destroy (&info->create_suspended_sem); - } - /* Run the actual main function of the thread */ start_routine_res = start_routine (start_routine_arg); @@ -1225,7 +1203,6 @@ mono_threads_create_thread (MonoThreadStart start, gpointer arg, MonoThreadParm thread_data->ref = 2; thread_data->start_routine = start; thread_data->start_routine_arg = arg; - thread_data->create_suspended = tp->creation_flags & CREATE_SUSPENDED; thread_data->priority = tp->priority; mono_coop_sem_init (&thread_data->registered, 0); diff --git a/mono/utils/mono-threads.h b/mono/utils/mono-threads.h index c81f3c6ba3f..5aafac7d7c2 100644 --- a/mono/utils/mono-threads.h +++ b/mono/utils/mono-threads.h @@ -221,11 +221,6 @@ typedef struct { */ gboolean is_async_context; - gboolean create_suspended; - - /* Semaphore used to implement CREATE_SUSPENDED */ - MonoCoopSem create_suspended_sem; - /* * Values of TLS variables for this thread. * This can be used to obtain the values of TLS variable for threads -- 2.25.1