Thread (11 messages) 11 messages, 3 authors, 2023-02-10
STALE1227d

[PATCH v6] win32: fix thread usage for win32

From: Rose via GitGitGadget <hidden>
Date: 2023-02-10 15:05:42
Subsystem: the rest · Maintainer: Linus Torvalds

From: Seija Kijin <redacted>

Use _beginthreadex instead of CreateThread
since we use the Windows CRT,
as Microsoft recommends _beginthreadex
over CreateThread for these situations.

Finally, check for NULL handles, not "INVALID_HANDLE,"
as _beginthreadex guarantees a valid handle in most cases

Signed-off-by: Seija Kijin <redacted>
---
    win32: fix thread usage for win32
    
    Use pthread_exit instead of async_exit.
    
    This means we do not have to deal with Windows's implementation
    requiring an unsigned exit coded despite the POSIX exit code requiring a
    signed exit code.
    
    Use _beginthreadex instead of CreateThread since we use the Windows CRT.
    
    Finally, check for NULL handles, not "INVALID_HANDLE," as _beginthreadex
    guarantees a valid handle in most cases
    
    Signed-off-by: Seija Kijin doremylover123@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1440%2FAtariDreams%2FCreateThread-v6
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1440/AtariDreams/CreateThread-v6
Pull-Request: https://github.com/git/git/pull/1440

Range-diff vs v5:

 1:  6ab79d9275d ! 1:  67cef4bd8c9 win32: fix thread usage for win32
     @@ compat/winansi.c: void winansi_init(void)
       
       	/* start console spool thread on the pipe's read end */
      -	hthread = CreateThread(NULL, 0, console_thread, NULL, 0, NULL);
     --	if (hthread == INVALID_HANDLE_VALUE)
     --		die_lasterr("CreateThread(console_thread) failed");
      +	hthread = (HANDLE)_beginthreadex(NULL, 0, console_thread, NULL, 0, NULL);
     -+	if (!hthread)
     + 	if (!hthread)
     +-		die_lasterr("CreateThread(console_thread) failed");
      +		die_lasterr("_beginthreadex(console_thread) failed");
       
       	/* schedule cleanup routine */


 compat/winansi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/compat/winansi.c b/compat/winansi.c
index f83610f684d..be65b27bd75 100644
--- a/compat/winansi.c
+++ b/compat/winansi.c
@@ -340,7 +340,7 @@ enum {
 	TEXT = 0, ESCAPE = 033, BRACKET = '['
 };
 
-static DWORD WINAPI console_thread(LPVOID unused)
+static unsigned int WINAPI console_thread(LPVOID unused)
 {
 	unsigned char buffer[BUFFER_SIZE];
 	DWORD bytes;
@@ -643,9 +643,9 @@ void winansi_init(void)
 		die_lasterr("CreateFile for named pipe failed");
 
 	/* start console spool thread on the pipe's read end */
-	hthread = CreateThread(NULL, 0, console_thread, NULL, 0, NULL);
+	hthread = (HANDLE)_beginthreadex(NULL, 0, console_thread, NULL, 0, NULL);
 	if (!hthread)
-		die_lasterr("CreateThread(console_thread) failed");
+		die_lasterr("_beginthreadex(console_thread) failed");
 
 	/* schedule cleanup routine */
 	if (atexit(winansi_exit))
base-commit: 23c56f7bd5f1667f8b793d796bf30e39545920f6
-- 
gitgitgadget
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help