Boost logo

Boost :

From: Jason Turner (lefticus_at_[hidden])
Date: 2007-03-06 16:54:04


Hi everyone. I've been lurking the mailing list for a couple of months
now and this is my first post.

I've been toying with an idea now for about 9 years, since college,
which I only just realized that C++ and specifically boost gives me
the tools that I need to implement it.

I am hoping someone on this list would be willing to comment on it, as
I hope to submit it for inclusion in boost relatively soon.

The general concept is that a calling thread never waits for the
return value of a function unless it needs to. In the case where a
function is being called, this means that a new thread is created for
a function call and an asynchronous return object is returned to the
caller. For instance:

active_object::active_return<int> ar =
    active_object::active_function(boost::function0<int>(&doStuff));

a boost::thread was just created which executes doStuff() and stores
the return value. The created thread is cleaned up at some later time
automatically (or during application shutdown).

The function template, active_function return immediately. The user
can then wait for doStuff to be completed when he is concerned about
it.

ar.wait_for_return();

or

int i = ar.value();

This makes creating parallel code almost trivial, which was the main
goal of the project, to make it easy to utilize newer multi-core
processors.

Similarly an active_object exists which creates a message thread for
an object and serializes all calls to the object:

The syntax for using an active_object is a little sloppy and I am not
sure I am 100% pleased with it:

  active_object::active_object<TestClass> ao(new TestClass());

  active_object::active_return<int> ar = ao << boost::function1<int,
TestClass *>(&TestClass::getInt);
  int v = ar.value();

It was only after setting out to implement the project did I realize
that this concept had been published a few years back under the name
"Active Object" (http://en.wikipedia.org/wiki/Active_Object) and there
are a couple of similar implementations floating around.

Project webpage:
http://source.emptycrate.com/projects/activeobjects/

Thanks
-Jason Turner

-- 
http://emptycrate.com Games, Programming, Travel & other stuff

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk