#include <iostream>
#include <boost/thread.hpp>
using namespace std;
//让方法只执行一次的标志
boost::once_flag once = BOOST_ONCE_INIT;
void func1()
{
cout<<"will be called but one time"<<endl;
}
void threadFunc()
{
//让方法只执行一次的操作
boost::call_once(&func1, once);
}
int main()
{
boost::thread_group group;
for (int i=0; i<6; ++i)
{
group.create_thread(threadFunc);
}
group.join_all();
system("pause");
return 0;
}
C++ Boost 多线程(七),线程的方法只执行一次
最新推荐文章于 2020-03-04 09:18:51 发布