#include <stdio.h>
#include <Windows.h>
struct Person
{
int personID;
int age;
};
DWORD WINAPI ThreadFun(LPVOID pM)
{
int i;
Person *me = (Person *)pM;
for (i = 0; i < 8; i++){
printf("子线程的线程ID号为:%d\n%d\n子线程输出Hello World\n",GetCurrentThreadId(),me->age);
Sleep(3000);
}
return 0;
}
int main()
{
printf("最简单的创建多线程实例\n");
Person *person=new Person();
person->age = 12;
person->personID = 1;
HANDLE handle = CreateThread(NULL, 0, ThreadFun, person, 0, NULL);
WaitForSingleObject(handle, INFINITE);
return 0;
}
C++多线程
最新推荐文章于 2024-08-01 09:46:25 发布