From: Vlad Brezae Date: Wed, 10 May 2017 23:14:11 +0000 (+0300) Subject: [runtime] Don't consume exception if not allowed to X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=055b15e0420a3dced029f95067865703f7fcbef9;p=mono.git [runtime] Don't consume exception if not allowed to The thread_state indicates whether we have a pending exception that needs to be consumed (be it sync or async). Normally we check the state before calling mono_thread_execute_interruption, but make sure we don't consume an exception if the thread_state doesn't allow us to (we can have an abort requested but mono_thread_clear_interruption_requested can return FALSE if we are inside an abort protected block and shouldn't process it) --- diff --git a/mono/metadata/threads.c b/mono/metadata/threads.c index 6ae7eaa0c72..5cc8e1d86f9 100644 --- a/mono/metadata/threads.c +++ b/mono/metadata/threads.c @@ -4435,14 +4435,17 @@ mono_thread_execute_interruption (void) LOCK_THREAD (thread); /* MonoThread::interruption_requested can only be changed with atomics */ - if (mono_thread_clear_interruption_requested (thread)) { - /* this will consume pending APC calls */ + if (!mono_thread_clear_interruption_requested (thread)) { + UNLOCK_THREAD (thread); + return NULL; + } + + /* this will consume pending APC calls */ #ifdef HOST_WIN32 - WaitForSingleObjectEx (GetCurrentThread(), 0, TRUE); + WaitForSingleObjectEx (GetCurrentThread(), 0, TRUE); #endif - /* Clear the interrupted flag of the thread so it can wait again */ - mono_thread_info_clear_self_interrupt (); - } + /* Clear the interrupted flag of the thread so it can wait again */ + mono_thread_info_clear_self_interrupt (); /* If there's a pending exception and an AbortRequested, the pending exception takes precedence */ if (sys_thread->pending_exception) {