首页 > 编程语言 > 详细

c++ 多线程

时间:2018-05-19 22:12:43      阅读:179      评论:0      收藏:0      [点我收藏+]

1.多线程初次使用:

// thread example
#include <iostream> 
#include <thread>
using namespace std;

void foo()
{
//do stuff
}

void bar(int x)
{
//do stuff
}

int main()
{
    thread first (foo); //spawn new thread that calls foo()
    thread second (bar, 0); //spawn new thread that calls bar(0)
    cout << "main, foo and bar now execute concurrently...\n";

    first.join();
    second.join();
    cout << "foo and bar completed.\n";
    return 0;

}

2.关于g++编译时候需要注意,不同g++版本可能不一样。

g++  thread.cpp -o thread -lpthread -std=c++11

c++ 多线程

原文:https://www.cnblogs.com/Shinered/p/9061824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!