• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
demps_c
博客园    首页    新随笔    联系   管理    订阅  订阅
boost第一个进程

1 #include <iostream>
2 #include <boost/thread.hpp>
3 using namespace std;
4 using namespace boost;
5 void hello(){
6 cout << "hello" << endl;
7 }
8 void f1(){
9 thread thr1(&hello);
10 thread thr2(&hello);
11 thread thr3(&hello);
12 thread thr4(&hello);
13 thr1.join();
14 thr2.join();
15 thr3.join();
16 thr4.join();
17 }
18
19 int main(){
20 f1();
21 return 0;
22 }

//本文件命名为thread.cpp

 

 

编译的时候使用的是g++ thread.cpp -lboost_thread-mt  

为什么要加上后面的-mt,呢,因为我在/usr/lib 文件夹里找到的是   

libboost_thread-mt.a
libboost_thread-mt.so
libboost_thread-mt.so.5 这三个文件,但是没有一个是没有-mt的,所以就是用了-mt

 而且要记住必须要那个join函数,要不就可能不会执行,让你看到输出了hello

 

posted on 2013-10-03 16:46  demps_c  阅读(510)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3