Unix to Windows Porting Dictionary for HPC |
|
|
RSS
LinksFunction List
|
Table of Contents header file: pthread.h
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void*), void *arg);
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
);
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. 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).
#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;
}
|
|
|
|