c++ thread线程join、detach、joinable方法
(621条消息) 线程中断Thread的interrupt()方法_thread interrupt_萝卜阿咕咕的博客-CSDN博客
C/C++编程:std::thread 详解-CSDN博客
#include <iostream>
#include <thread>void do_some_work()
{std::cout<<"Hello Concurrent World\n";
}int main()
{std::thread t(do_some_work);t.join();
}#include<thread>
#include<iostream>int main()
{std::thread t([](){std::cout<< "lambda thread"<< std::endl; });t.join();std::cout << "resume main thread" << std::endl;return 0;
}// 打印结果lambda thread
resume main thread
C++:std::thread:线程用法_std::thread用法-CSDN博客
join、detach、joinable方法
C++多线程:线程的创建、join、detach、joinable方法(二)_c++ joinable-CSDN博客
#include <iostream>
#include <thread>void thread_func1()
{std::cout << "子线程开始执行" << std::endl;std::cout << "子线程执行完毕" << std::endl;
}int main()
{std::thread mythread1(thread_func1);if(mythread1.joinable()){std::cout << "joinable() == true" << std::endl;mythread1.join();}else{std::cout << "joinable() == false" << std::endl;}std::cout << "------------------------------" << std::endl;if(mythread1.joinable()){std::cout << "joinable() == true" << std::endl;}else{std::cout << "joinable() == false" << std::endl;}std::cout << "main thread executed finish!" << std::endl;return 0;
}
joinable方法
- joinable方法主要判断是否可以使用join方法或者detach方法,可以返回true,不可以返回false
- 一个线程最多只能调用一次join或者detach
使用make_shared <std :: thread>创建shared_ptr <std :: thread>的实例 | (1r1g.com)
C++ std::thread的基础使用和管理 - 今天的小马同学 - 博客园 (cnblogs.com)
std::thread thread_(&MobileComSettingsClient::subscribeNotifyThread,this);//thread_.join(); //阻塞thread_.detach(); //分离
(359条消息) C++11多线程_lie to me的博客-CSDN博客_c++11 多线程
(360条消息) C++11中5种创建线程方法_求则得之,舍则失之的博客-CSDN博客_c++新建线程