码迷,mamicode.com
首页 > 编程语言 > 详细

C++11 std::thread在类的成员函数中的使用

时间:2019-12-18 09:22:33      阅读:317      评论:0      收藏:0      [点我收藏+]

标签:har   sign   name   join()   c++   turn   wrapper   read   nbsp   

1.

#include <thread>
#include <iostream>
using namespace std;
class Wrapper { public: void member1() { cout << "member1" << endl; }
void member2(const char *arg1, unsigned arg2) { cout << "i am member2 and my first arg is ("
         << arg1 << ") and second arg is ("
         << arg2 << ")" <<endl; }
std::thread member1Thread() {
return thread(&Wrapper::member1, this); }
std::thread member2Thread(
const char *arg1, unsigned arg2) { return thread(&Wrapper::member2, this, arg1, arg2); } }; int main() { Wrapper *w = new Wrapper(); std::thread tw1 = w->member1Thread(); tw1.join(); w->member2Thread("hello", 100).detach(); return 0; }

 

C++11 std::thread在类的成员函数中的使用

标签:har   sign   name   join()   c++   turn   wrapper   read   nbsp   

原文地址:https://www.cnblogs.com/mathyk/p/12058028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!