一、類的普通成員函數作爲Thread的參數
class threadtest
{
private:
public:
threadtest() { }
~threadtest() { }
// 類的普通成員函數
void test_fun1(int num) {
for (int i = 0; i < num; i++)
cout << "thread test1" << endl;
return;
}
};
threadtest tt;
thread th1(&threadtest::test_fun1, &tt, 10);
th1.join();
二、類的靜態成員函數作爲Thread的參數
class threadtest
{
private:
public:
threadtest() { }
~threadtest() { }
// 類的靜態成員函數
static void test_fun2(string str) {
for(int i = 0; i < 10; i++) {
cout << str << endl;
}
}
};
threadtest tt;
thread th2(&threadtest::test_fun2, "thread test2");
th2.join();
三、普通函數作爲Thread的參數
// 普通函數
void test_fun3(string str) {
for(int i = 0; i < 10; i++) {
cout << str << endl;
}
}
thread th3(test_fun3, "thread test3");
th3.join();