课程1
- thread:线程,process:进程,进程包含线程;
- t1.join() 等待t1线程执行完再继续;
- t1.detach() 不等待t1完成,如果另外的线程运行太快,t1可能不被执行;
课程2
- 类可以构造线程;
class Fctor{
public:
void operator()(){
for(int i = 0;i > -100; i--)
std::cout << "from t1:" << i << std::endl;
}
};
int main(){
//
Fctor fct;
thread t1(fct);
//
//
thread t1((Fctor()));
//
- d
课程8 使用可调用对象
- 创立线程的两种方式:
std::thread t1(a, 6);
std::async(std::launch::async, a, 6);
- 创建子线程
std::thread t1(a, 6);
std::thread t1(std::ref(a), 6);
std::thread t1(std::move(a), 6);
std::thread t4(A(), 6);
std::thread t5(foo, 6);
std::thread t6([](int x){return x*x;}, 6);
std::thread t7(&A::f, a, 8, 'w');
std::thread t8(&A::f, &a, 8, 'w');