Looping dependencies

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Looping dependencies

Luca Billi
I noticed that the current implementation of LazyObjects generates
infinite recursions
in the case the dependency hierarchy among Observer/Observable objects
contains loops.

A suggestion to break the infinite recursion is to replace the update()
method as follows:

 void LazyObject::update() {

      if (!frozen_&& calculated_){
        //
        // Set calculated_=false before calling notifyObservers()
        //
        calculated_ = false;

        notifyObservers();
      }

      calculated_ = false;
 }


Luca

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Looping dependencies

Luigi Ballabio
Luca,
    thanks for the report.  Ferdinando applied your changes to the repository.

Luigi

On Sun, Feb 5, 2012 at 9:26 PM, Luca Billi <[hidden email]> wrote:

> I noticed that the current implementation of LazyObjects generates
> infinite recursions
> in the case the dependency hierarchy among Observer/Observable objects
> contains loops.
>
> A suggestion to break the infinite recursion is to replace the update()
> method as follows:
>
>  void LazyObject::update() {
>
>      if (!frozen_&& calculated_){
>        //
>        // Set calculated_=false before calling notifyObservers()
>        //
>        calculated_ = false;
>
>        notifyObservers();
>      }
>
>      calculated_ = false;
>  }
>
>
> Luca
>
> ------------------------------------------------------------------------------
> Try before you buy = See our experts in action!
> The most comprehensive online learning library for Microsoft developers
> is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
> Metro Style Apps, more. Free future releases when you subscribe now!
> http://p.sf.net/sfu/learndevnow-dev2
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Looping dependencies

Ferdinando M. Ametrano-3
In reply to this post by Luca Billi
Hi Luca


On Sun, Feb 5, 2012 at 9:26 PM, Luca Billi <[hidden email]> wrote:
> I noticed that the current implementation of LazyObjects generates
> infinite recursions
> in the case the dependency hierarchy among Observer/Observable objects
> contains loops.
>
> A suggestion to break the infinite recursion is to replace the update()
> method as follows:
> [...]

good catch, even if on the 1.2.0 release branch it was already fixed as in the following

   inline void LazyObject::update() {
       // forwards notifications only the first time
       if (calculated_) {
           // set to false early, otherways non-lazy observers would be
           // served obsolete data because of calculated_ being still true
           calculated_ = false;
           // observers don't expect notifications from frozen objects
           if (!frozen_)
               notifyObservers();
       }
   }


I've added your "prevent infinite recursion" comment too

ciao -- Nando

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev