C++ thread function

1. Create a thread
function prototype
CreateThread(
    _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
    _In_ SIZE_T dwStackSize,
    _In_ LPTHREAD_START_ROUTINE lpStartAddress,
    _In_opt_ __drv_aliasesMem LPVOID lpParameter,
    _In_ DWORD dwCreationFlags,
    _Out_opt_ LPDWORD lpThreadId
    );

parameter (security descriptor
           the initial size of the stack
            thread function
            Parameters passed to the thread
            thread creation flag
            thread identifier)

Security descriptor : The lpThreadAttributes member specifies the security descriptor for the new thread. If lpThreadAttributes is NULL, the thread will get the default security descriptor.

Stack initial size : If this parameter is 0, the default size of 1M is used.

Thread function: This pointer represents the starting address of the thread. See ThreadProc for details.
thread parameter: pointer to a variable to be passed to the thread.

Flag for thread creation: 0 means run immediately after creation. CREATE_SUSPENDED means create in a suspended state.
thread identifier: If this parameter is  NULL , no thread identifier is returned .

Function return value: Returns a handle if the thread was created successfully. Return NULL on failure.

2. Suspend the thread

function prototype
DWORD WINAPI SuspendThread(
  在_HANDLE hThread
);

hThread: The thread handle to suspend.
Function return value: Returns the thread's previous pause count if the function succeeds.

3. Resume thread

function prototype

DWORD WINAPI ResumeThread(
  在_HANDLE hThread
);
hThread: The thread handle to restart.
Function return value: Returns the thread's previous pause count if the function succeeds. Returns -1 on failure.
4. End the thread
function prototype
BOOL WINAPI TerminateThread(
  _Inout_ HANDLE hThread,
  _In_ DWORD dwExitCode
);

hThread: The thread handle to terminate.
dwExitCode: The exit code of the thread. Usually force quit is -1.

Function return value: The function returns 0 if it succeeds, and non-zero if it fails.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324823623&siteId=291194637