This is in continuation of the previous article 'Windows Threading Vs. Linux Threading', here we'll see a subtle but significant difference in the thread start routine which gets a call from CreateThread() API in the Windows world or pthread_create() function call in the Linux world.
The ThreadProc function in Windows:
DWORD WINAPI ThreadProc(
_In_ LPVOID lpParameter
);
This is an application-defined function that serves as the starting address for a thread.
Note: As per MSDN, Do not declare this callback function with a void return type and cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread.
Code that does this is common, but it can crash on 64-bit Windows.
The return value indicates the success or failure of this function. The return value should never be set to STILL_ACTIVE (259).
In Linux: The function passed as start_routine in the pthread_create() function should correspond to the following C function prototype:
void *threadStartRoutinName(void *);
This is one of the differences we need to take care of while writing thread start routines between Windows and Linux.
The ThreadProc function in Windows:
DWORD WINAPI ThreadProc(
_In_ LPVOID lpParameter
);
This is an application-defined function that serves as the starting address for a thread.
Note: As per MSDN, Do not declare this callback function with a void return type and cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread.
Code that does this is common, but it can crash on 64-bit Windows.
The return value indicates the success or failure of this function. The return value should never be set to STILL_ACTIVE (259).
In Linux: The function passed as start_routine in the pthread_create() function should correspond to the following C function prototype:
void *threadStartRoutinName(void *);
This is one of the differences we need to take care of while writing thread start routines between Windows and Linux.
Comments