Boost logo

Boost :

From: Hurd, Matthew (hurdm_at_[hidden])
Date: 2004-02-23 23:43:37

> On Behalf Of Matthew Vogt
> Subject: [boost] Re: [Threads] Simple active object wrapper, take 2
> >Hurd, Matthew <hurdm <at>> writes:
> > Had a little thought that might be relevant. Please spank me if
this is
> > OT given the rather specific implementation I'm dropping in on...
> >
> Not at all. If this proves useful, I would certainly want to support
> > As mentioned previously, future values could give you a lazy way of
> > evaluating the result, even when you aren't multithreaded.
> >
> > In the truly "active" object, that is, it has at least one thread,
> > could call the methods with a future instead of a normal value so
> > when the result arrives it percolates through the implied queue.
> >
> > Now for a new thought. What about using an expression template
> > mechanism so that when you combine futures they are glommed at
> > time to remain lazy?
> >
> > boost::future<double> sum =;
> > boost::future<double> count = some_thing_maybe_active.count();
> > boost::future<double> average = sum / count;
> >
> > sum / count forms a lazy expression
> >
> > if a method groks a future and then this becomes interesting...
> >
> > boost::future<double> result =
> > some_thing_maybe_active.do_stuff(average);
> >
> > You can end up with the active object percolating all the way
through to
> > "result" without any blocking until the result of "result" is used.
> >
> Yes, certainly. I'm not au fait with expression templates, but you
> alternatively implement arithmetic operations in future<T> which
> maintained
> shared pointers to operands, and stored a function pointer to
> etc.

Expression templates are just a way of doing the kind of thing you have
just described at compile time. Here is a famous intro that I like anyway.

> > If you get rid of the thread(s) in the active object idea, you end
> > with a mechanism for lazy evaluation.
> >
> This I don't really follow. If you take away the thread from the
> object
> then the calling thread must perform the evaluation itself,
> What
> you have left is equivalent to a sequence of boost::binds to a
> function, haven't you?

No, it doesn't have to perform the operation, the future could simply
contain a boost::optional<value> with a boost::function callback, for
one example implementation, so the calc might not be done until it is
really needed...

I was thinking about this situation in terms of what it would take to
move this successfully to a single threaded (or passive object?) case
and the problem of messy dependencies that automagically resolve
themselves in the threaded active object sense might not have a
solution, or might have a less efficient solution, if laziness was not
the default behaviour. That is you could end up waiting on things that
haven't been kicked off and thus you deadlock without laziness.

> > Perhaps there is a more general mechanism / pattern and bike shop
> > lurking in this pattern...
> >
> > Regards,
> >
> > Matt Hurd
> Are you suggesting that the 'future' template is a convenient
> sugar
> for lazy evaluation, as a separate concern to the threading involved?
> so,
> I can't disagree...
> Matt

Yup, laziness and possibly a neat way of keeping things architectural
neutral with appropriate policies.


Matt Hurd

Susquehanna Pacific P/L

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Boost list run by bdawes at, gregod at, cpdaniel at, john at