c++11多线程---
标签:std this ++ 成员 class http code color include
1、普通函数(线程入口)
#include
#include void hello(const char *name) {
std::cout "Hello " std::endl;
}
int main() {
std::thread thread(hello, "C++11"); //函数名、参数
thread.join(); //等待线程执行完毕
return 0;
}
2、类成员函数(线程入口)
#include
#include class Greet
{
const char *owner = "Greet";
public:
void SayHello(const char *name) {
std::cout "Hello " " from " this->owner std::endl;
}
};
int main() {
Greet greet;
std::thread thread(&Greet::SayHello, &greet, "C++11"); //传入成员函数地址、 类对象地址、参数
thread.join();
return 0;
}
//输出:Hello C++11 from Greet
https://www.jianshu.com/u/88ad4f76eb79
c++11多线程---
标签:std this ++ 成员 class http code color include
原文地址:https://www.cnblogs.com/lovebay/p/11579041.html
评论