码迷,mamicode.com
首页 > Windows程序 > 详细

win32 - WaitForMultipleObjects的使用

时间:2020-07-22 20:14:34      阅读:80      评论:0      收藏:0      [点我收藏+]

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

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

#include <Windows.h>
#include <stdio.h>

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 < NBOFTHREADS; 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!