您的位置:首页 > 其它

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;  

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: