colorful

zc qq:1337220912

 

关于boost::thread 的一件怪事

本想测试printf的线程安全的,结果发现boost::thread的一件有趣的事,见代码
#include <cstdio>
#include 
<boost/thread.hpp>
#include 
<boost/bind.hpp>

int fun1()
{
   
for(int i=0; i<10; i++)
      printf(
"哈哈哈哈哈哈\n");
   
return 0;
}

int fun2(int count)
{
   
for(int i=0; i<count; i++)
      printf(
"呵呵呵呵呵呵\n");
   
return 0;
}

int main()
{
   boost::thread(fun1);     
// 不以打印
   boost::thread(fun2, 10); // 可以打印
   boost::thread t(fun1);   // 可以打印

   getchar();
   
return 0;
}
不知什么原因,知道的可以告诉我吗

posted on 2012-05-14 21:50 多彩人生 阅读(315) 评论(0)  编辑 收藏 引用 所属分类: boost


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


导航

统计

常用链接

留言簿(3)

随笔分类

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜