Boost logo

Boost Users :

Subject: Re: [Boost-users] async processing issues
From: Igor R (boost.lists_at_[hidden])
Date: 2013-07-04 04:46:53


> boost::asio::io_service service1;
> boost::asio::io_service service2;
>
> // dir_monitor callback running in thread 1
> void f_handler(const boost::system::error_code &ec, const
> boost::asio::dir_monitor_event &ev)
> {
> TaskObj tsk = new TaskObj(...);
> // detect event, create task and post functor to thread 2 which handles
> // tasks
>
> service2.post(boost::bind(&TaskObj::do_it, tsk));
> }
>
> int main(...) {
> boost::asio::dir_monitor dm(service1);
>
> for (/*directory list*/) {
> dm.add_directory(dir);
> }
>
> dm.async_monitor(f_handler);
>
> // setup work to prevent exit and before running io_service
> shared_ptr<boost::asio::io_service::work>
> work(new boost::asio::io_service::work(service2));
>
>
> // thread to constantly monitor dirs
> boost::thread t1 =
> boost::thread(boost::bind(&boost::asio::io_service::run,
> boost::ref(service1)));

First of all, I don't know how dir_monitor works (it's not a part of
an official Boost.Asio). But if its interface semantic is consistent
with other Asio interfaces, than async_monitor should asynchronously
monitor 1 event. So, after async_monitor gets completed, service1 runs
out of work and its run() loop exits (not that you didn't give it any
"work" object).


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