线程对象可以和一般对象一样,其所有权可以被转移,示例如下:
#include <iostream>
#include <thread>
void get(std::thread&& t)
{
t.detach();
int a;
std::cin >> a;
std::cout << a << std::endl;
}
void task(const char* sz)
{
std::cout << sz << std::endl;
}
int main()
{
std::thread th(task, "i come from there!");
get(std::move(th));
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)