标签:打印 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