线程的创建-5

来源:互联网 发布:java随机生成26个字母 编辑:程序博客网 时间:2024/06/09 23:35
#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");
}
0 0