知识屋:更实用的电脑技术知识网站
所在位置:首页 > 社会

C++ 多线程实例

发表时间:2022-03-25来源:网络

 使用C++实现多线程实例【ubuntu16.04环境 C++11】

需要引用头文件:`thread` 【C++11线程标准库】

注意:编译时 g++ -o main -lpthread -std=c++11

如果不添加编译选项:`lpthread`  则会报错:`collect2: error: ld returned 1 exit status`

 

 多线程代码实例

#include #include using namespace std; thread::id main_thread_id = this_thread::get_id(); //获取当前线程的句柄id void hello() //测试单线程 { if (this_thread::get_id() == main_thread_id) { cout
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜