Hi,

I tried to follow your suggestion by not using ioservice.reset
By doing so, it is not entering into the while loop again for xexcuting another query with the set of threads in the pool.

I was using work.reset to merge the results that come out of my first iteration of while loop
After every iteration, I need to merge results that are computed by the threads.

So, I used work.reset and again using post in the loop to post qnother query for the set of threads in the pool.

Please review my piece of code. Iam sure that I missed some valuable point in my code that is causing this strange behaviour.

Please suggest me a solution for this as I got stuck with the same.

Thanks for your immediate responses.

Regards,


On Sunday, 13 July 2014 6:22 PM, Lars Viklund <zao@acc.umu.se> wrote:


On Sun, Jul 13, 2014 at 08:11:23PM +0800, imran sheikh wrote:
> hi ,
>
> but if i am not using ioservice.reset() in the while loop then second time the threads are not executing properly.
> so please give me a strong running solution .i need immediately this one.

Hi there,

You appear to be missing some knowledge about how the operations on an
io_service fits together.

When you post a handler to an io_service, it will (eventually) run on
any thread that happens to do any of run(), run_one(), poll(),
poll_one().

The io_service will be in the running state as long as there exists
'work', operations in progress (like send/recv), or posted handlers in
queue.

Important here is that if the io_service runs out of things to do, it
finishes and returns from the run() functions.

The typical lifecycle of an io_service are:

== Setup ==
* prepare and post operations to it;
* construct instances of 'work' to artificially keep it alive;
* run one or more run()/run_one()/poll()/poll_one() somewhere.

== Runtime ==
* do things with devices, timers, post handlers, etc.

== Teardown ==
* destroy any artifical 'work' objects that you use to keep it running;
* stop posting more operations and handlers to it, so it runs out;
* optionally wait for it and any worker threads to finish.

For the scenario of a thread pool that runs posted handlers; the typical
approach is:

* make control 'work';
* create N threads, running run();
* post handlers until bored;
* destroy control 'work';
* join all N threads.

The reset() function shall only be called after the io_service is
stopped and you wish to eventually re-start it [1]. It's an error to
call reset() while you're run()ing.

[1] http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/io_service/reset.html


--
Lars Viklund | zao@acc.umu.se
_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users