win32 - WaitForMultipleObjects的使用
Posted strive-sun
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了win32 - WaitForMultipleObjects的使用相关的知识,希望对你有一定的参考价值。
创建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. ", 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. ", i, IDs[i]); lpHandles[i] = Threadhandle; } WaitForMultipleObjects(NBOFTHREADS, lpHandles, TRUE, INFINITE); return 0; }
以上是关于win32 - WaitForMultipleObjects的使用的主要内容,如果未能解决你的问题,请参考以下文章