#include <iostream>
#include <thread>
#include <windows.h>
#include <vector>
using namespace std;
using namespace std::this_thread;
void msgA(int num)
{
cout <<get_id()<< " num=" << num << endl;
}
void main()
{
vector<thread *> threads;
for (int i = 0; i < 10;i++)
{
threads.push_back(new thread(msgA, i));//创建一个线程
}
for (auto th: threads)
{
th->join();
}
system("pause");
}
#include <thread>
#include <windows.h>
#include <vector>
using namespace std;
using namespace std::this_thread;
void msgA(int num)
{
cout <<get_id()<< " num=" << num << endl;
}
void main()
{
vector<thread *> threads;
for (int i = 0; i < 10;i++)
{
threads.push_back(new thread(msgA, i));//创建一个线程
}
for (auto th: threads)
{
th->join();
}
system("pause");
}