Posted by
Henner Heck on
URL: http://quantlib.414.s1.nabble.com/Issues-with-C-Swig-Bindings-NUnit-and-Settings-instance-setEvaluationDate-tp9517p9524.html
Hello all,
>> Might be worth checking if there is a situation in which
>> setEvaluationDate gets called from a constructor of an object? This
>> probably isn't a good idea and could lead to partially constructed
>> objects that you are seeing.
Concluding from my code, it had to be partially deconstructed objects.
The actual problem was the list of raw pointers "observers_" in the
QuantLib::Observable class. It could happen, that the Java garbage collector,
which is running in it's own thread, collects/destructs an observer object
while an observable of this observer happens to be iterating over it's
observers_ list. It could come across a partially deconstructed object
(to the point where it becomes a QuantLib::Observer) which has no implementation
of "update()" anymore except the pure virtual one of Observer.
Therefore the "pure virtual function call" error happens.
I first tried to resolve this by making the update() function not pure.
That resolved this particular error, but now an "EXCEPTION_ACCESS_VIOLATION (0xc0000005)"
occurred, probably because of messing around with the list structure while iterating over it.(?)
My guess is, that this error could have appeared before also, but that the
"pure virtual function call" was just much more probable.
I also unsuccessfully tried some locking of functions, but in the end i chose to abandon
the raw pointer list completely. My solution now is to use the "enable_shared_from_raw.hpp" from
Boost in combination with Boost:signals2 to maintain trackable connections between Observer and Observable.
It seems to work for my scenario. A loop of 20000 swapevaluations went through without crashing.
Unfortunately "enable_shared_from_raw.hpp" is from the Boost trunk and not (yet?)
part of the official releases. You can easily get it here (you'll need the "shared_ptr.hpp" too):
http://svn.boost.org/svn/boost/trunk/boost/smart_ptr/
There will be some complaints from the compiler about ambiguous declarations
in some anonymous namespaces and about inaccessible base class:
/QuantLib/ql/pricingengines/vanilla/analytichestonengine.cpp
replace "_1" with "boost::lambda::_1"
replace "bind" with "boost::lambda::bind"
/QuantLib/test-suite/inflationvolatility.cpp
/QuantLib/test-suite/nthtodefault.cpp
replace "smart_ptr" with "boost::smart_ptr"
/QuantLib/ql/experimental/finitedifferences/fdmsimple2dbssolver.hpp
make the inheritance from LazyObject in line 40 public:
"class FdmSimple2dBSSolver : public LazyObject {"
I attached the modified "observable.hpp", in case someone's interested to give it a try.
The condition for it to work is that each Observer has to be under the control of a
boost::shared_ptr when constructed.
The mutex is not really needed in a "single thread +gc"-only scenario, but it didn't give
me a noticeable performance decrease, so i kept it. Feel free to comment it out.
The modified code passed the QuantLib 1.0.1 testsuite using Visual Studio Express 2008
(32 Bit compilation, release static) on Windows 7 Professional 64 Bit.
Best regards,
Henner Heck
> On Tue, 2011-01-04 at 19:29 +0100, Henner Heck wrote:
>> Here is one quick scenario i got from the debugger [...] The observer
>> at index 13 is recognized only as Observer, which seems odd, and it is
>> also the observer in which update() fails (this == 0x19ef7398). It
>> seems to me that it is not a fully constructed/destructed IborCoupon
>> object.
>
> Yes, it seems so. Strange... Is there any chance that we can reproduce
> this in C++?
>
> Luigi
>
>
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev