Using the thread pool in boost

Source: Internet
Author: User

#include <boost/thread/thread.hpp>
#include <boost/bind.hpp>
#include <iostream>

Using namespace boost;
Using namespace std;

void runchild (const int  n
{
    cout  <<  "I am the first  << n  <<  "Child Threads"  << endl     Sleep     cout <<  "process"  < Span class= "sy1" ><< n <<   "exit"  << endl /span>

int main (int argc,  Char** argv)
{
     int num     Thread_group threads

if (argc < 2)
{
cout << "Please provide a parameter to generate the number of threads" << Endl;
Exit(-1);
}

num = atoi(argv[1]);

cout<<"I am the main program, and I am ready to produce"<< num<<"Child Threads"<< Endl;
For(int I=0; I< num; i++)
    {
        Threads. Create_thread&runchild, I     }
    cout < <  "I am the main program, I am waiting for the child thread to run the end"  << endl;
    Threads. join_all (     return 0 /span>

Compile & Test (I tested it under my Ubuntu)

> g++ Threadgroup.cc-lboost_thread
>./a.out 3

If you compile under FREEBSD4, if you use pthread as the thread implementation, you need to make it clear that Pthread uses the line libraries, and that the default template depth does not seem to meet the boost demand. Need to be added at compile time:

-ftemplate-depth-20-boost

Using the thread pool in boost

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.