// // Linux: compile using // g++ -std=c++17 threads_printer.cpp -pthread // #include #include #include #include #include #include #include namespace demo{ class Printer{ private: std::mutex printmtx_; public: void print(std::string file, int x) { std::lock_guard lock(printmtx_); std::cout << "thread id "< ths; for(int i=0; i<10; i++){ std::thread th(job,i); ths.push_back(std::move(th)); // must use std::move } for(auto &th: ths) th.join(); // must use auto & }