Unix to Windows Porting Dictionary for HPC

RSS

Links

Function List

pthread_create


Unix

header file: pthread.h

int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                   void *(*start_routine)(void*), void *arg);
      

Windows

header file: Windows.h

HANDLE WINAPI CreateThread(
  __in_opt   LPSECURITY_ATTRIBUTES lpThreadAttributes,
  __in       SIZE_T dwStackSize,
  __in       LPTHREAD_START_ROUTINE lpStartAddress,
  __in_opt   LPVOID lpParameter,
  __in       DWORD dwCreationFlags,
  __out_opt  LPDWORD lpThreadId
);
      

Purpose

The pthread_create function is used to create a new thread with attributes specified by attr and a starting address specified in start_routine within in the current process. If the function is successful, the ID of the newly created thread is returned in thread.

Discussion

The Windows equivalent function has more options (security attributes, stack size and creation flags) than the POSIX version. These options can be set to either NULL (security attributes) or zero (stack size and creation flags).

Example of Use in Windows

#include <stdio.h>
#include <windows.h>

DWORD WINAPI newThreadFunc(LPVOIDarg) 
{ 
printf("Hello World from the new thread\n"); 
return 0; 
}

main() 
{
printf("Hello World from the main program\n"); 
HANDLE hThread= CreateThread(NULL,0,newThreadFunc,NULL,0,NULL);
return 0;
}
    
blog comments powered by Disqus
Valid HTML 4.01 Transitional Valid CSS!