![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c++多线程
Jeff_ROS
路漫漫,上下求索!!!
展开
-
Thread函数的参数传递和线程所有权转移(2.2)--std::move()
先上代码:void f(int i,std::string const & s);std::thread t(f,"hello");第一个参数是线程函数名,第二个参数是函数的参数。但是注意一点,当提供参数是自动变量的指针时,如:void fn(int i, std::string const & s);void opp(int some_param){ char buffer[10原创 2016-10-19 09:40:19 · 4832 阅读 · 1 评论 -
用C++11的std::async代替线程的创建
c++11中增加了线程,使得我们可以非常方便的创建线程,它的基本用法是这样的:void f(int n);std::thread t(f, n + 1);t.join();但是线程毕竟是属于比较低层次的东西,有时候使用有些不便,比如我希望获取线程函数的返回结果的时候,我就不能直接通过thread.join()得到结果,这时就必须定义一个变量,在线程函数中去给这个变量赋值,然翻译 2016-10-19 22:46:04 · 691 阅读 · 0 评论