标签:style c class blog code http
转自:http://www.justsoftwaresolutions.co.uk/threading/multithreading-in-c++0x-part-3.html
是个just的c++库。和c11很像。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
#include <thread> #include <iostream> class
SayHello { public : void
greeting(std::string const & message) const { std::cout<<message<<std::endl; } }; int
main() { SayHello x; std:: thread
t(&SayHello::greeting,&x, "goodbye" ); t.join(); } |
栈上的对象,需要确保生命期比thread长。否则可以用 std::shared_ptr<SayHello> 确保对象存在,只要线程没死。
1
2
3
4
5
6 |
int
main() { std::shared_ptr<SayHello> p( new
SayHello); std:: thread
t(&SayHello::greeting,p, "goodbye" ); t.join(); } |
标签:style c class blog code http
原文地址:http://www.cnblogs.com/bigben0123/p/3745027.html