git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] win32: use _endthreadex to terminate threads, not ExitThread
@ 2022-12-22 20:59 Rose via GitGitGadget
  2022-12-24  8:01 ` Johannes Sixt
  2022-12-25  1:41 ` [PATCH v2] " Rose via GitGitGadget
  0 siblings, 2 replies; 5+ messages in thread
From: Rose via GitGitGadget @ 2022-12-22 20:59 UTC (permalink / raw)
  To: git; +Cc: Rose, Seija Kijin

From: Seija Kijin <doremylover123@gmail.com>

This is a pretty serious bug actually:
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
    
    This is a pretty serious bug actually: 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-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1414/AtariDreams/severe-bug-v1
Pull-Request: https://github.com/git/git/pull/1414

 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
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] win32: use _endthreadex to terminate threads, not ExitThread
  2022-12-22 20:59 [PATCH] win32: use _endthreadex to terminate threads, not ExitThread Rose via GitGitGadget
@ 2022-12-24  8:01 ` Johannes Sixt
  2022-12-25  1:41 ` [PATCH v2] " Rose via GitGitGadget
  1 sibling, 0 replies; 5+ messages in thread
From: Johannes Sixt @ 2022-12-24  8:01 UTC (permalink / raw)
  To: Rose via GitGitGadget; +Cc: Seija Kijin, git

Am 22.12.22 um 21:59 schrieb Rose via GitGitGadget:
> From: Seija Kijin <doremylover123@gmail.com>
> 
> This is a pretty serious bug actually:
> 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>
> ---

>  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;

Nice find! FWIW, this passes the test suite on Windows.

The patch text is:

Acked-by: Johannes Sixt <j6t@kdbg.org>

The commit message is highly exaggerated, though. The bug is by no means
serious. After all, we've been living with it for a decade. Notice that
pthread_exit() is only called when a thread runs into die(). Even though
we have a small memory leak, it does not occur in a loop because, after
one thread dies, we do not tend to keep starting many, many more that
all die.

-- Hannes


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] win32: use _endthreadex to terminate threads, not ExitThread
  2022-12-22 20:59 [PATCH] win32: use _endthreadex to terminate threads, not ExitThread Rose via GitGitGadget
  2022-12-24  8:01 ` Johannes Sixt
@ 2022-12-25  1:41 ` Rose via GitGitGadget
  2022-12-25  8:54   ` Johannes Sixt
  1 sibling, 1 reply; 5+ messages in thread
From: Rose via GitGitGadget @ 2022-12-25  1:41 UTC (permalink / raw)
  To: git; +Cc: Johannes Sixt, Rose, Seija Kijin

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
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] win32: use _endthreadex to terminate threads, not ExitThread
  2022-12-25  1:41 ` [PATCH v2] " Rose via GitGitGadget
@ 2022-12-25  8:54   ` Johannes Sixt
  2022-12-25 12:40     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Sixt @ 2022-12-25  8:54 UTC (permalink / raw)
  To: Rose via GitGitGadget; +Cc: Seija Kijin, git

Am 25.12.22 um 02:41 schrieb Rose via GitGitGadget:
> 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] win32: use _endthreadex to terminate threads, not ExitThread
  2022-12-25  8:54   ` Johannes Sixt
@ 2022-12-25 12:40     ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2022-12-25 12:40 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Rose via GitGitGadget, Seija Kijin, git

Johannes Sixt <j6t@kdbg.org> writes:

> Am 25.12.22 um 02:41 schrieb Rose via GitGitGadget:
>> From: Seija Kijin <doremylover123@gmail.com>
>>  ...
> Thank you! This patch is now
>
> Acked-by: Johannes Sixt <j6t@kdbg.org>

Thanks.  Will queue.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-25 12:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-22 20:59 [PATCH] win32: use _endthreadex to terminate threads, not ExitThread Rose via GitGitGadget
2022-12-24  8:01 ` Johannes Sixt
2022-12-25  1:41 ` [PATCH v2] " Rose via GitGitGadget
2022-12-25  8:54   ` Johannes Sixt
2022-12-25 12:40     ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).