vs 2022中创建多线程并传参

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
    int n = (int)lpParameter;
    printf("Hello from the new thread!\n");
    printf("n = %d !\n",n);
    return 0;
}

int main()
{
    HANDLE hThread = CreateThread(NULL, 0, ThreadProc, (LPVOID)(1 + 1), 0, NULL);
    if (hThread == NULL) {
        printf("Failed to create thread.\n");
        return 1;
    }
    printf("Failed to create thread.\n");
    Sleep(5000);
    // 等待新线程完成  
    WaitForSingleObject(hThread, INFINITE);

    // 关闭线程句柄  
    CloseHandle(hThread);

    return 0;
}

你可能感兴趣的:(C语言,TPM,java,前端,服务器)