Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] posting a function to an io_service object
From: Vilhelm Sundberg (vilhelmsundberg_at_[hidden])
Date: 2009-12-28 16:04:48


> You use io_service incorrectly, please see asio tutorial/examples.
>
>>    while (ios1.poll() > 0)
>>        ;
>>    while (ios2.poll() > 0)
>>        ;
>
> io_services are already running - in other threads - why do you poll()
> them here?
In this example, poll() is there to execute the f() handlers and wait
for them to finish.

You are right, not polling the io_services from the main thread makes
the f() calls run in the other threads as intended. In that case is
there a way to check from the main thread if the io_services finished
executing the posted handlers (some kind of a peek())?

I have a program where there are several parallel io_threads and I
want to run two distinct library functions in each io_service first
thing an io_service is started and last thing before an io_service is
stopped. These functions are posted from the main thread. My problem
is with the function that is to be executed last: how can I wait for
that to be executed before stopping the io_service and joining the
thread? Calling poll()/dispatch() from the main thread is not an
option, it seems.

Vil


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net