From: Giovanni P. Deretta (gpderetta_at_[hidden])
Date: 2006-10-17 17:50:27
Dean Michael Berris wrote:
> Hi everyone,
> I'm working on a project right now which uses both Boost.Asio and
> Boost.Thread along with a lot of other Boost libraries. We've pretty
> much had to roll our own Active Object implementation everytime we
> need asynchronous method invocation, and I understand that Futures are
> being proposed for C++0x.
> The question would be whether there will be (or whether there already
> is) a "generic" active object implementation? We've found that
> Boost.Asio's io_service is a good scheduler/queue and using a futures
> wrapper for the result types.
> Perhaps something that used some preprocessor magic or with some TMP ?
> Insights and pointers will be most appreciated.
In the coroutine library I've developed as part of the summer of code,
I've used futures to represent asynchronous function invocations, that
is the result of an asynchronous computations , not necessarily
concurrent. Every computation whose result can be delivered using an
asio io_service can be represented by a future. This model can very well
be used to represent active objects, in fact asio sort of already does
that: the resolver service can be considered an active object (it uses a
worker thread to run the actual resolver), and a future can be used to
wait for the result of an async_resolve function.
These futures are tightly bound to coroutines (i.e. you can use them
only from inside a coroutine), and they might or might not fit in your
existing design. When a coroutine wait for a future, control is
relinquished to the io_service that can do other work.
About preprocessor and TMP magic, I'm using some of it to have futures
be able to handle any number and types result types (for example an
async_write returns a future<error_type, std::size_t>.
While the road to a full active object is long, may be my library is a
good start. BTW, coroutines might be a much better way,
performance-wise, to implement Active Objects with one thread per object
or a thread pool.
You can look at the code and see if it fits your need here:
Currently real life prevent me from cleaning up the library for a boost
review request, but plan to do it short term.
-- Giovanni P. Deretta
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk