git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] win32: use _endthreadex to terminate threads, not ExitThread

From
Johannes Sixt <j6t@kdbg.org>
Date
Dec 25, 2022, 08:54 UTC
Message-ID
<983ce25f-82e1-e20d-ffb5-fd04fa9a9231@kdbg.org>
In-Reply-To
<pull.1414.v2.git.git.1671932510529.gitgitgadget@gmail.com>
Am 25.12.22 um 02:41 schrieb Rose via GitGitGadget:
Show 62 quoted lines
> From: Seija Kijin <doremylover123@gmail.com>
> 
> Because we use the C runtime and
> use _beginthreadex to create pthreads,
> pthread_exit MUST use _endthreadex.
> 
> Otherwise, according to Microsoft:
> "Failure to do so results in small
> memory leaks when the thread
> calls ExitThread."
> 
> Simply put, this is not the same as ExitThread.
> 
> Signed-off-by: Seija Kijin <doremylover123@gmail.com>
> ---
>     win32: use _endthreadex to terminate threads, not ExitThread
>     
>     Because we use the C runtime and use _beginthread to create pthreads,
>     pthread_exit MUST use _endthread.
>     
>     Otherwise, according to Microsoft: "Failure to do so results in small
>     memory leaks when the thread calls ExitThread."
>     
>     Simply put, this is not the same as ExitThread.
>     
>     Signed-off-by: Seija Kijin doremylover123@gmail.com
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1414%2FAtariDreams%2Fsevere-bug-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1414/AtariDreams/severe-bug-v2
> Pull-Request: https://github.com/git/git/pull/1414
> 
> Range-diff vs v1:
> 
>  1:  78f9d54c304 ! 1:  3e8212fb9a7 win32: use _endthreadex to terminate threads, not ExitThread
>      @@ Metadata
>        ## Commit message ##
>           win32: use _endthreadex to terminate threads, not ExitThread
>       
>      -    This is a pretty serious bug actually:
>           Because we use the C runtime and
>           use _beginthreadex to create pthreads,
>           pthread_exit MUST use _endthreadex.
> 
> 
>  compat/win32/pthread.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h
> index 737983d00ba..cc3221cb2c8 100644
> --- a/compat/win32/pthread.h
> +++ b/compat/win32/pthread.h
> @@ -66,7 +66,7 @@ pthread_t pthread_self(void);
>  
>  static inline void NORETURN pthread_exit(void *ret)
>  {
> -	ExitThread((DWORD)(intptr_t)ret);
> +	_endthreadex((unsigned)(uintptr_t)ret);
>  }
>  
>  typedef DWORD pthread_key_t;
> 
> base-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7
Thank you! This patch is now
Acked-by: Johannes Sixt <j6t@kdbg.org>
-- Hannes
Previous: Rose via GitGitGadgetNext: Junio C Hamano
Message 4 of 5 in “win32: use _endthreadex to terminate threads, not ExitThread”
  1. win32: use _endthreadex to terminate threads, not ExitThreadRose via GitGitGadget, Dec 22, 2022
  2. Johannes SixtDec 24, 2022
  3. win32: use _endthreadex to terminate threads, not ExitThreadRose via GitGitGadget, Dec 25, 2022
  4. Johannes SixtDec 25, 2022
  5. Junio C HamanoDec 25, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.