- A function pointer
void cbThread(int params)
{
std::cout << "HelloWorld" << std::endl;
}
std::thread threadObj(cbThread, 5);
- A function1 object
class MyThread {
public:
void run(int params) {
std::cout << "HelloWorld" << std::endl;
}
}:
std::thread threadObj(&MyThread::run, MyThread());
- A function2 object
class MyThread {
public:
void operator()(int params) {
std::cout << "HelloWorld" << std::endl;
}
}:
std::thread threadObj(MyThread(), 5);
- A lambda expression
std::thread threadObj([](int params){
std::cout << "HelloWorld" << std::endl;
});
沒有留言:
張貼留言