1) Creation of threads
Create a function - the function on the MSDN
Handle CreateThread
LPSecurity_attributes LPTHREADATIADATTRIBUTES,
Size_t dwstacksize,
LPTHREAD_START_ROUTINE LPSTARTDRESS,
LPVOID LPPARETER,
DWORD DWCREATIONFLAGS,
LPDWORD LPTHREADID
);
The first parameter pthreadAttribute is a function of the security property and start setting up to the default security attribute NULL
The second parameter DWSTACKSIZE is the size of the stack page that starts assigning the thread can be set to the default size 0
The entry function of the third parameter LPStartAddress thread can be set
DWORD WINAPI FUN1PRO (LPVOID LPPARETER);
The fourth is the parameter passed to the thread, the type is a pointer type can be null
The fifth parameter dwcreationFlags refers to when the thread is called if it is crete_suspended, the thread is not running when it is created.
Until the ResumeThread function
If 0, then start running after the thread is created;
The sixth parameter lpthreadID is used to transfer thread ID if null is NULL
Here is a thread program I started.
DWORD WINAPI Fun1Pro (LPVOID lpParameter); void main () {HANDLE hThread1; hThread1 = CreateThread (NULL, 0, Fun1Pro, NULL, 0, NULL); CloseHandle (hThread1); cout << "main thread run" << endl; }
DWORD WINAPI FUN1PRO (LPVOID LPPARETER) {COUT << "Thread2 Is Run" << Endl; Return 0;}
This program is not ideal, that is, when the main thread is completed, the process I created is not running. The result is that the result is: When the main thread is executed, the main thread exits, the main thread exits, then it The process of creation is to exit, this is the reason for Thread2 Is Run;
In order to make the creation can run, always introduce a SLEEP function, call the function at the exit of the main function, allow the main thread to be temporarily running, and then say that the main thread gives up the CPU, so the process of creation is Opportunity executed void main () {handle hthread1; hthread1 = Createthread (NULL, 0, FUN1PRO, NULL, 0, NULL); CloseHandle (HTHREAD1); COUT << "Main Thread Run" <<
Sleep (10);