Update 23.11.2015: The latest version is now part of the official QuantLib Release 1.7.
Update 22.09.2015: Please find the latest and improved version of the patch for QuantLib 1.6.2 here.
The usage of QuantLib in JVM and .NET languages (e.g. Java/Scala and C#/F#) via the SWIG interface has a known shortcoming. The implementation of QuantLib’s observer pattern does not tolerate a parallel garbage collector running in a different thread. As a result programs are randomly crashing or producing “pure virtual function calls”. A detailed description of this problem can be found e.g. here and within the references.
Please find here a patch for QuantLib 1.4 to fix this issue. It contains
- Riccardo’s thread-safe singleton patch
- Thread-safe Observer pattern based on boost::signals2
- Irakli’s static data initialisation via function call
Installation instructions are included in the readme.txt file.
4 thoughts on “QuantLib-SWIG Patch for JVM/.NET Languages”
Hi Klaus, with the current trunk the markov tests should run reasonably fast again, so I guess starting with 1.5 you can include them in your patch again. Best, Peter
thanks for your help on this topic. I’ll put the Markov tests back in when 1.5 is out.
Hi Klaus, I know memory management in python works differently than JVM/.Net VM but I was wondering if this solution would also work as thread-safe solution via Swig-Python? Perhaps there are certain parts of the patch which would not be needed? Regards, Joe
The patch should work for Python as well because (I guess) the Python interpreter uses the same OS threads as the boost library. IMO you don’t need the patch for Python 2.x.
You’ll need all parts of the patch.