1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include <iostream> #include <thread>
void hello(std::string& str) { str = "123"; }
int main(int argc, const char * argv[]) { std::string s("abc"); std::thread my_thread(hello, std::ref(s)); my_thread.join(); std::cout << s << std::endl; return 0; }
class X { public: void do_lengthy_work(); }; X my_x; std::thread t(&X::do_lengthy_work,&my_x);
|