win32 - WaitForMultipleObjects的使用

2020-12-27 06:26

阅读:773

标签:打印   started   run   wait   内容   int   ted   expected   bsp   

创建5个线程,并无限期地打印某些内容

#include 
#include 

DWORD IDs[5];

DWORD WINAPI ThreadProc(LPVOID TID) {
    //expected this block to run infinitely.
    while (1) {
        printf("Inside Thread: %d. \n", TID);
        Sleep(1000);
    }

    return 0;
}

#define NBOFTHREADS 5

int main() {
    HANDLE lpHandles[NBOFTHREADS];

    for (int i = 0; i ) {
        HANDLE Threadhandle = CreateThread(0, 0, ThreadProc, &IDs[i], 0, &IDs[i]);
        printf("Thread %d -> ID %d started. \n", i, IDs[i]);
        lpHandles[i] = Threadhandle;
    }

    WaitForMultipleObjects(NBOFTHREADS, lpHandles, TRUE, INFINITE);
    return 0;
}

 

win32 - WaitForMultipleObjects的使用

标签:打印   started   run   wait   内容   int   ted   expected   bsp   

原文地址:https://www.cnblogs.com/strive-sun/p/13362020.html


评论


亲,登录后才可以留言!