關(guān)于boost::thread 的一件怪事
本想測試printf的線程安全的,結(jié)果發(fā)現(xiàn)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;
}
不知什么原因,知道的可以告訴我嗎
#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 多彩人生 閱讀(338) 評論(0) 編輯 收藏 引用 所屬分類: boost