Skip to content

Commit

Permalink
win32: fix thread usage for win32
Browse files Browse the repository at this point in the history
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 <doremylover123@gmail.com>
  • Loading branch information
GameCubeGBA authored and AtariDreams committed Jan 31, 2023
1 parent 2fc9e9c commit 6ab79d9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions compat/winansi.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
if (hthread == INVALID_HANDLE_VALUE)
die_lasterr("CreateThread(console_thread) failed");
hthread = (HANDLE)_beginthreadex(NULL, 0, console_thread, NULL, 0, NULL);
if (!hthread)
die_lasterr("_beginthreadex(console_thread) failed");

/* schedule cleanup routine */
if (atexit(winansi_exit))
Expand Down

0 comments on commit 6ab79d9

Please sign in to comment.