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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 22.12.22 um 21:59 schrieb Rose via GitGitGadget:
> From: Seija Kijin <doremylover123@xxxxxxxxx>
> 
> 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@xxxxxxxxx>
> ---

>  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@xxxxxxxx>

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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux