Serving the Quantitative Finance Community

 
User avatar
kevin08
Topic Author
Posts: 0
Joined: October 24th, 2008, 11:42 pm

QuantLib exception safety

February 1st, 2010, 2:24 am

It may sound paranoid, but copy contractor, assignment and registerWith methods of Observable class aren't exception safe. The danger maybe purely theoretical, though. If Observable::registerObserver throws, then some of the objects mey be corrupted. What do you think?Below is copy&paste from 1.0 beta
Last edited by kevin08 on January 31st, 2010, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 22937
Joined: July 16th, 2004, 7:38 am

QuantLib exception safety

February 1st, 2010, 5:17 am

QuoteIt may sound paranoid, but copy contractor, assignment and registerWith methods of Observable class aren't exception safe. The danger maybe purely theoretical, though. If Observable::registerObserver throws, then some of the objects mey be corruptedFrom the code, an exception could occur when pushing an observer onto the attention list? It's not obvious what the problems could be.What about boost Signal/Signal2 that is boost's implementation of the Observer pattern? Do you want thread-safe as well?
Last edited by Cuchulainn on January 31st, 2010, 11:00 pm, edited 1 time in total.
 
User avatar
kevin08
Topic Author
Posts: 0
Joined: October 24th, 2008, 11:42 pm

QuantLib exception safety

February 1st, 2010, 12:25 pm

If (*i)->registerObserver(this) in Observer's copy constructor fails, some of the observables may end up with the copy of soon to be dead pointer this.If h->registerObserver(this) in Observer::registerWith fails, then h won't add this to its attention list, but this will be linked to the observable h.If observables_ = o.observables_; in Observer's assignment operator fails, then this will end up with empty list of observables. But if (*i)->registerObserver(this) fails, then this will register only with some of the observables.As for boost signals, the documentation states that connecting slots is strongly exception safe.
 
User avatar
dicesare
Posts: 1
Joined: July 14th, 2002, 3:00 am

QuantLib exception safety

February 1st, 2010, 2:47 pm

QuoteOriginally posted by: kevin08If (*i)->registerObserver(this) in Observer's copy constructor fails, some of the observables may end up with the copy of soon to be dead pointer this.If h->registerObserver(this) in Observer::registerWith fails, then h won't add this to its attention list, but this will be linked to the observable h.If observables_ = o.observables_; in Observer's assignment operator fails, then this will end up with empty list of observables. But if (*i)->registerObserver(this) fails, then this will register only with some of the observables./q]Hi,Registering in a try/catch block and unregistering when exception is catched should be good.