Fixed ExitThread, now running pthread_exit and setting event.
authorArmin Novak <armin.novak@thincast.com>
Wed, 16 Jul 2014 10:08:34 +0000 (12:08 +0200)
committerArmin Novak <armin.novak@thincast.com>
Mon, 27 Oct 2014 10:28:13 +0000 (11:28 +0100)
winpr/include/winpr/thread.h
winpr/libwinpr/thread/thread.c

index 83a398c..54e9e19 100644 (file)
@@ -163,7 +163,7 @@ WINPR_API HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T d
 WINPR_API HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize,
                LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId);
 
-WINPR_API VOID ExitThread(DWORD dwExitCode);
+WINPR_API DECLSPEC_NORETURN VOID ExitThread(DWORD dwExitCode);
 WINPR_API BOOL GetExitCodeThread(HANDLE hThread, LPDWORD lpExitCode);
 
 WINPR_API HANDLE _GetCurrentThread(void);
index e3ed524..5c287dc 100644 (file)
@@ -425,6 +425,12 @@ VOID ExitThread(DWORD dwExitCode)
                backtrace(thread->exit_stack, 20);
 #endif
                ListDictionary_Unlock(thread_list);
+               set_event(thread);
+
+               if (thread->detached || !thread->started)
+                       cleanup_handle(thread);
+
+               pthread_exit(thread->dwExitCode);
        }
 }
 
@@ -537,7 +543,7 @@ VOID DumpThreadHandles(void)
 #if defined(HAVE_EXECINFO_H)
        backtrace(stack, 20);
 #endif
-  fprintf(stderr, "---------------- %s ----------------------\n", __FUNCTION);
+       fprintf(stderr, "---------------- %s ----------------------\n", __FUNCTION);
        fprintf(stderr, "---------------- Called from ----------------------------\n");
 #if defined(HAVE_EXECINFO_H)
        backtrace_symbols_fd(stack, 20, STDERR_FILENO);