void CTask1::work()
{
while (true) {
cout<<"Task1"<<endl;
std::this_thread::sleep_for(chrono::seconds(1));
}
}
//static void work1();
void CTask1::work1()
{
while (true) {
cout<<"Task0 static"<<endl;
std::this_thread::sleep_for(chrono::seconds(1));
}
}
void CTask2::work()
{
while (true) {
cout<<"Task2"<<endl;
std::this_thread::sleep_for(chrono::seconds(1));
}
}
int main(int argc, char *argv[])
{
//直接使用函数
thread th0(CTask1::work1);
//使用类成员函数
CTask1 task1;
thread th1(&CTask1::work, &task1);
//使用bind
CTask2 task2;
thread th2(bind(&CTask2::work, &task2));
//使用lambda
thread th3([](){
while (true) {
cout<<"lambda th"<<endl;
this_thread::sleep_for(chrono::seconds(1));
}
});
th0.join();
th1.join();
th2.join();
th3.join();
return 1;
}