c++11多线程---

2020-12-13 15:21

阅读:694

标签: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

上一篇:A*算法介绍

下一篇:C语言复习


评论


亲,登录后才可以留言!