多線程使用


DWORD WINAPI  ThreadProc(LPVOID pParam)
{
    CString s;
    s.Format(L"Thread %d finished\r\n", pParam);
    OutputDebugString(s);
    return 0;   // thread completed successfully
}


const int num = 4;
HANDLE g_h[num];
void OnTest()
{    
    for (int i = 0; i < num; i++)
    {
        DWORD id;
        g_h[i] = CreateThread(NULL, 0, ThreadProc, (LPVOID)i, CREATE_SUSPENDED, &id);
        ResumeThread(g_h[i]);
    }
    
    WaitForMultipleObjects(num, g_h, TRUE, INFINITE);
    

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章