centos(x86 64位系统)使用boost过程

本文介绍了如何在C++中使用Boost库实现并发任务,并通过示例代码展示了如何创建线程和执行不同任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



1. 安装gcc,g++,make等开发环境

yum groupinstall "Development Tools"


2. 安装boost

 yum install boost boost-devel boost-doc

注意:默认的安装路径在/usr/lib64目录下


3. 例子

  1. #include <boost/thread.hpp>  
  2. #include <iostream>  
  3.   
  4. void task1() {   
  5.     // do stuff  
  6.     std::cout << "This is task1!" << std::endl;  
  7. }  
  8.   
  9. void task2() {   
  10.     // do stuff  
  11.     std::cout << "This is task2!" << std::endl;  
  12. }  
  13.   
  14. int main (int argc, char ** argv) {  
  15.     using namespace boost;   
  16.     thread thread_1 = thread(task1);  
  17.     thread thread_2 = thread(task2);  
  18.   
  19.     // do other stuff  
  20.     thread_2.join();  
  21.     thread_1.join();  
  22.     return 0;  
  23. }  
4. makefile

g++ -I./inlcude -L./usr/lib64  asio_thread.cpp -lboost_thread-mt  -o example
注意:默认的安装路径在/usr/lib64目录下
5.结果
This is task2!
This is task1!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值