'boost::thread'에 해당되는 글 1건

  1. 2008.10.20 boost::asio::io_service working thread 여러개 설정
2008. 10. 20. 14:01

boost::asio::io_service working thread 여러개 설정

boost::asio::io_server의 win32 platform은 CompletionPort를 사용한다. 

한심하게도, 얼마전까지 io_service내부에서 working thread가 관리되는걸로 생각하고 있었다.

그런지만 그럴지가 없지 않은가? CompletionPort나 내부적으로 Proactor패턴을 구현하고 있다고 얼마전 포스팅에서 쓴적이 있는데, io_service내부에서 thread를 관리할 이유가 없는 것이다.

어쨋거나, working thread는 외부에서 여러개 실행해서, bind시켜 주면 된다.

아래와 같이 말이다.

        const int numofthread = 5;
        boost::thread_group    threadg; 

        for( int i = 0; i < numofthread; i++ )

        {

               threadg.create_thread(boost::bind(&boost::asio::io_service::run, &io_service));

        }

        threadg.join_all();

        return 0;