On Friday, 11 July 2014 11:00 PM, imran sheikh <s.imran0508@yahoo.com> wrote:


hi all,
i am using boost::asio:: ioservice  for the multi-threading in c++. i got stuck ...please see and help.
code is like this,

discription:
> i am creating threadpool using ioservice.
> creating threads 100.
> in while (which is 5 times)loop at a time i want to post(posting at do work) 5 threads.
> then i do work reset and like this..
>i print thread-id also

problems::

>threadpool size is 100.
> but at a posting time it didn't taking the 5 threads..when i printed a id its same for 5 thread
> so its not executing in parallel..why?
> i want to post five threads at a time(different threads means thread id is different  must)..from threapool..and like this for whole while loop rotation..??????????????????????????

void dowork(int i)
{
std::cout<<"hello"<<std::endl;
cout<<" thread ID :"<<boost::this_thread::get_id();
}


int main()
{
int ch;
int i;
boost::asio::io_service ioservice;
boost::thread_group threadpool;
auto_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(ioservice));
for(i=0;i<100;i++)
{
threadpool.create_thread( boost::bind(&boost::asio::io_service::run, &ioservice));
}
        ch=0;
        while(ch <= 5)
        {
                ch++;
                cout<<"in main"<<boost::this_thread::get_id()<<endl;
                                for(i=0;i<5;i++)
                                {
                                ioservice.post(boost::bind(dowork,10));
                                }
                std::cout<<"size="<<threadpool.size()<<std::endl;
                work.reset();
               ioservice.reset();
                ioservice.run();
    }
}

please give me suggestion.i got stuck with it.