boost库中thread多线程详解6——线程组简单例子
2013-09-01 16:16
441 查看
[cpp] view
plaincopyprint?
namespace
{
struct Run
{
void operator()(void)
{
std::cout << __FUNCTION__ << std::endl;
}
};
void run(void)
{
std::cout << __FUNCTION__ << std::endl;
}
}
void test_thread_group2()
{
Run r;
boost::thread_group grp;
// 两种方法通过线程组增加线程
boost::thread *t = grp.create_thread(r); // 使用create_thread
grp.add_thread(new boost::thread(run)); // 使用add_thread
grp.join_all();
// 两种方法移除线程
grp.remove_thread(t);
// delete t;
}
plaincopyprint?
namespace
{
struct Run
{
void operator()(void)
{
std::cout << __FUNCTION__ << std::endl;
}
};
void run(void)
{
std::cout << __FUNCTION__ << std::endl;
}
}
void test_thread_group2()
{
Run r;
boost::thread_group grp;
// 两种方法通过线程组增加线程
boost::thread *t = grp.create_thread(r); // 使用create_thread
grp.add_thread(new boost::thread(run)); // 使用add_thread
grp.join_all();
// 两种方法移除线程
grp.remove_thread(t);
// delete t;
}
相关文章推荐
- 【Boost】boost库中thread多线程详解6——线程组简单例子
- 【Boost】boost库中thread多线程详解6——线程组简单例子
- 【Boost】boost库中thread多线程详解7——wait与timed_wait简单例子
- 【Boost】boost库中thread多线程详解7——wait与timed_wait简单例子
- 【Boost】boost库asio详解9——TCP的简单例子2
- boost库中thread多线程详解
- 【Boost】boost库中thread多线程详解1
- 【Boost】boost库中thread多线程详解4——谈谈recursive_mutex(递归式互斥量)
- 【Boost】boost库中thread多线程详解2——mutex与lock
- 【Boost】boost库中thread多线程详解12——线程的分离与非分离
- boost库中thread多线程详解2——mutex与lock
- 【Boost】boost库中thread多线程详解2——mutex与lock
- 【Boost】boost库中thread多线程详解3——细说lock_guard
- boost库中thread多线程详解3——细说lock_guard
- 【Boost】boost库中thread多线程详解4——谈谈recursive_mutex
- 【Boost】boost库中thread多线程详解13——线程标识符
- boost库中thread多线程详解2——mutex与lock
- 【Boost】boost库中thread多线程详解5——谈谈线程中断
- 【Boost】boost库中thread多线程详解4——谈谈recursive_mutex(递归式互斥量)
- 【Boost】boost库asio详解9——UDP的简单例子1