使用标准c++库创建线程

3年以前  |  阅读数:452 次  |  编程语言:C++ 
#include<iostream>
#include<thread>

using namespace std;

void thread1() {
    for(int i=0;i<20;++i)
        cout << "thread1..." << endl;
}

void thread2() {
    for (int i = 0; i<20; ++i)
        cout << "thread2..." << endl;
}

int main(int argc, char* argv[]) {
    thread th1(thread1);   //实例化一个线程对象th1,该线程开始执行
    thread th2(thread2);
    cout << "main..." << endl;
    return 0;
}

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8