{"thread":{"id":"58996","subject":"[PATCH] win32: use _endthreadex to terminate threads, not ExitThread","startedAt":"2022-12-22T20:59:17Z","lastAt":"2022-12-25T12:45:50Z","messageCount":5,"participants":["Rose via GitGitGadget","Johannes Sixt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"469480","messageId":"pull.1414.git.git.1671742750504.gitgitgadget@gmail.com","threadId":"58996","inReplyTo":null,"subject":"[PATCH] win32: use _endthreadex to terminate threads, not ExitThread","fromName":"Rose via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-12-22T20:59:10Z","receivedAt":"2022-12-22T20:59:17Z","isPatch":true,"sender":{"key":"ckelsch@jgrcpa.com","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\nThis is a pretty serious bug actually:\nBecause we use the C runtime and\nuse _beginthreadex to create pthreads,\npthread_exit MUST use _endthreadex.\n\nOtherwise, according to Microsoft:\n\"Failure to do so results in small\nmemory leaks when the thread\ncalls ExitThread.\"\n\nSimply put, this is not the same as ExitThread.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    win32: use _endthreadex to terminate threads, not ExitThread\n    \n    This is a pretty serious bug actually: Because we use the C runtime and\n    use _beginthread to create pthreads, pthread_exit MUST use _endthread.\n    \n    Otherwise, according to Microsoft: \"Failure to do so results in small\n    memory leaks when the thread calls ExitThread.\"\n    \n    Simply put, this is not the same as ExitThread.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1414%2FAtariDreams%2Fsevere-bug-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1414/AtariDreams/severe-bug-v1\nPull-Request: https://github.com/git/git/pull/1414\n\n compat/win32/pthread.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/compat/win32/pthread.h b/compat/win32/pthread.h\nindex 737983d00ba..cc3221cb2c8 100644\n--- a/compat/win32/pthread.h\n+++ b/compat/win32/pthread.h\n@@ -66,7 +66,7 @@ pthread_t pthread_self(void);\n \n static inline void NORETURN pthread_exit(void *ret)\n {\n-\tExitThread((DWORD)(intptr_t)ret);\n+\t_endthreadex((unsigned)(uintptr_t)ret);\n }\n \n typedef DWORD pthread_key_t;\n\nbase-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7\n-- \ngitgitgadget\n"},{"id":"469506","messageId":"0b039029-97ce-bbc3-d9af-7f1eb1fd8b64@kdbg.org","threadId":"58996","inReplyTo":"pull.1414.git.git.1671742750504.gitgitgadget@gmail.com","subject":"Re: [PATCH] win32: use _endthreadex to terminate threads, not ExitThread","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2022-12-24T08:01:11Z","receivedAt":"2022-12-24T08:01:18Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 22.12.22 um 21:59 schrieb Rose via GitGitGadget:\n> From: Seija Kijin <doremylover123@gmail.com>\n> \n> This is a pretty serious bug actually:\n> Because we use the C runtime and\n> use _beginthreadex to create pthreads,\n> pthread_exit MUST use _endthreadex.\n> \n> Otherwise, according to Microsoft:\n> \"Failure to do so results in small\n> memory leaks when the thread\n> calls ExitThread.\"\n> \n> Simply put, this is not the same as ExitThread.\n> \n> Signed-off-by: Seija Kijin <doremylover123@gmail.com>\n> ---\n\n>  compat/win32/pthread.h | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h\n> index 737983d00ba..cc3221cb2c8 100644\n> --- a/compat/win32/pthread.h\n> +++ b/compat/win32/pthread.h\n> @@ -66,7 +66,7 @@ pthread_t pthread_self(void);\n>  \n>  static inline void NORETURN pthread_exit(void *ret)\n>  {\n> -\tExitThread((DWORD)(intptr_t)ret);\n> +\t_endthreadex((unsigned)(uintptr_t)ret);\n>  }\n>  \n>  typedef DWORD pthread_key_t;\n\nNice find! FWIW, this passes the test suite on Windows.\n\nThe patch text is:\n\nAcked-by: Johannes Sixt <j6t@kdbg.org>\n\nThe commit message is highly exaggerated, though. The bug is by no means\nserious. After all, we've been living with it for a decade. Notice that\npthread_exit() is only called when a thread runs into die(). Even though\nwe have a small memory leak, it does not occur in a loop because, after\none thread dies, we do not tend to keep starting many, many more that\nall die.\n\n-- Hannes\n\n"},{"id":"469516","messageId":"pull.1414.v2.git.git.1671932510529.gitgitgadget@gmail.com","threadId":"58996","inReplyTo":"pull.1414.git.git.1671742750504.gitgitgadget@gmail.com","subject":"[PATCH v2] win32: use _endthreadex to terminate threads, not ExitThread","fromName":"Rose via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-12-25T01:41:50Z","receivedAt":"2022-12-25T01:41:57Z","isPatch":true,"sender":{"key":"ckelsch@jgrcpa.com","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\nBecause we use the C runtime and\nuse _beginthreadex to create pthreads,\npthread_exit MUST use _endthreadex.\n\nOtherwise, according to Microsoft:\n\"Failure to do so results in small\nmemory leaks when the thread\ncalls ExitThread.\"\n\nSimply put, this is not the same as ExitThread.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    win32: use _endthreadex to terminate threads, not ExitThread\n    \n    Because we use the C runtime and use _beginthread to create pthreads,\n    pthread_exit MUST use _endthread.\n    \n    Otherwise, according to Microsoft: \"Failure to do so results in small\n    memory leaks when the thread calls ExitThread.\"\n    \n    Simply put, this is not the same as ExitThread.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1414%2FAtariDreams%2Fsevere-bug-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1414/AtariDreams/severe-bug-v2\nPull-Request: https://github.com/git/git/pull/1414\n\nRange-diff vs v1:\n\n 1:  78f9d54c304 ! 1:  3e8212fb9a7 win32: use _endthreadex to terminate threads, not ExitThread\n     @@ Metadata\n       ## Commit message ##\n          win32: use _endthreadex to terminate threads, not ExitThread\n      \n     -    This is a pretty serious bug actually:\n          Because we use the C runtime and\n          use _beginthreadex to create pthreads,\n          pthread_exit MUST use _endthreadex.\n\n\n compat/win32/pthread.h | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/compat/win32/pthread.h b/compat/win32/pthread.h\nindex 737983d00ba..cc3221cb2c8 100644\n--- a/compat/win32/pthread.h\n+++ b/compat/win32/pthread.h\n@@ -66,7 +66,7 @@ pthread_t pthread_self(void);\n \n static inline void NORETURN pthread_exit(void *ret)\n {\n-\tExitThread((DWORD)(intptr_t)ret);\n+\t_endthreadex((unsigned)(uintptr_t)ret);\n }\n \n typedef DWORD pthread_key_t;\n\nbase-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7\n-- \ngitgitgadget\n"},{"id":"469517","messageId":"983ce25f-82e1-e20d-ffb5-fd04fa9a9231@kdbg.org","threadId":"58996","inReplyTo":"pull.1414.v2.git.git.1671932510529.gitgitgadget@gmail.com","subject":"Re: [PATCH v2] win32: use _endthreadex to terminate threads, not ExitThread","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2022-12-25T08:54:22Z","receivedAt":"2022-12-25T08:54:34Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 25.12.22 um 02:41 schrieb Rose via GitGitGadget:\n> From: Seija Kijin <doremylover123@gmail.com>\n> \n> Because we use the C runtime and\n> use _beginthreadex to create pthreads,\n> pthread_exit MUST use _endthreadex.\n> \n> Otherwise, according to Microsoft:\n> \"Failure to do so results in small\n> memory leaks when the thread\n> calls ExitThread.\"\n> \n> Simply put, this is not the same as ExitThread.\n> \n> Signed-off-by: Seija Kijin <doremylover123@gmail.com>\n> ---\n>     win32: use _endthreadex to terminate threads, not ExitThread\n>     \n>     Because we use the C runtime and use _beginthread to create pthreads,\n>     pthread_exit MUST use _endthread.\n>     \n>     Otherwise, according to Microsoft: \"Failure to do so results in small\n>     memory leaks when the thread calls ExitThread.\"\n>     \n>     Simply put, this is not the same as ExitThread.\n>     \n>     Signed-off-by: Seija Kijin doremylover123@gmail.com\n> \n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1414%2FAtariDreams%2Fsevere-bug-v2\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1414/AtariDreams/severe-bug-v2\n> Pull-Request: https://github.com/git/git/pull/1414\n> \n> Range-diff vs v1:\n> \n>  1:  78f9d54c304 ! 1:  3e8212fb9a7 win32: use _endthreadex to terminate threads, not ExitThread\n>      @@ Metadata\n>        ## Commit message ##\n>           win32: use _endthreadex to terminate threads, not ExitThread\n>       \n>      -    This is a pretty serious bug actually:\n>           Because we use the C runtime and\n>           use _beginthreadex to create pthreads,\n>           pthread_exit MUST use _endthreadex.\n> \n> \n>  compat/win32/pthread.h | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/compat/win32/pthread.h b/compat/win32/pthread.h\n> index 737983d00ba..cc3221cb2c8 100644\n> --- a/compat/win32/pthread.h\n> +++ b/compat/win32/pthread.h\n> @@ -66,7 +66,7 @@ pthread_t pthread_self(void);\n>  \n>  static inline void NORETURN pthread_exit(void *ret)\n>  {\n> -\tExitThread((DWORD)(intptr_t)ret);\n> +\t_endthreadex((unsigned)(uintptr_t)ret);\n>  }\n>  \n>  typedef DWORD pthread_key_t;\n> \n> base-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7\n\nThank you! This patch is now\n\nAcked-by: Johannes Sixt <j6t@kdbg.org>\n\n-- Hannes\n\n"},{"id":"469523","messageId":"xmqqedsnodvb.fsf@gitster.g","threadId":"58996","inReplyTo":"983ce25f-82e1-e20d-ffb5-fd04fa9a9231@kdbg.org","subject":"Re: [PATCH v2] win32: use _endthreadex to terminate threads, not ExitThread","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-12-25T12:40:40Z","receivedAt":"2022-12-25T12:45:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n> Am 25.12.22 um 02:41 schrieb Rose via GitGitGadget:\n>> From: Seija Kijin <doremylover123@gmail.com>\n>>  ...\n> Thank you! This patch is now\n>\n> Acked-by: Johannes Sixt <j6t@kdbg.org>\n\nThanks.  Will queue.\n"}]}