|
From: Eric E. <eri...@re...> - 2020-11-14 10:46:12
|
OK, I will take a crack at it before the next release. I hope that I
can recreate the error somehow, otherwise it will be hard to test the fix.
Kind Regards,
Eric
On 11/14/20 9:25 AM, SX L wrote:
> I don't have a github account yet, and I am an old fashion coder still
> using svn. However, the change is simple as below. If I were to go
> into multithread later, I would dump or re-design Singleton pattern,
> which is notorious for multithread.
>
> Index: ql/patterns/singleton.hpp
> ===================================================================
> --- ql/patterns/singleton.hpp (revision 130)
> +++ ql/patterns/singleton.hpp (working copy)
> @@ -160,7 +160,7 @@
> T& Singleton<T>::instance() {
>
> #if (QL_MANAGED == 0) && !defined(QL_SINGLETON_THREAD_SAFE_INIT)
> - static std::map<ThreadKey, ext::shared_ptr<T> > instances_;
> + static T instances_;
> #endif
>
> // thread safe double checked locking pattern with atomic
> memory calls
> @@ -185,9 +185,7 @@
> ThreadKey id = 0;
> #endif
>
> - ext::shared_ptr<T>& instance = instances_[id];
> - if (!instance)
> - instance = ext::shared_ptr<T>(new T);
> + T* instance = &instances_;
>
> #endif
>
> ------------------------------------------------------------------------
> *From:* Eric Ehlers <eri...@re...>
> *Sent:* Wednesday, November 11, 2020 4:35 AM
> *To:* SX L <han...@ho...>
> *Cc:* qua...@li...
> <qua...@li...>
> *Subject:* Re: [Quantlib-users] ObservableSettings is deleted early
> than Observables.
>
> Hi Philip,
>
> Would you be willing to submit a pull request?
>
> Regards,
> Eric
>
> On 11/10/20 5:21 AM, SX L wrote:
>> Hi Eric,
>>
>> Thanks for looking into this issue. Yes, I identified the issue in my
>> windows x64 debug version. The issue could be hard to reproduce since
>> my release version gives me normal exit code. It really depends on
>> the sequence of calling dtors of those shared pointers at exit.
>>
>> So I would suggest moving away from shared pointers in Singletons.
>> Create a singltonDestroyer or use static instances.
>>
>> Get Outlook for Android <https://aka.ms/ghei36>
>>
>> ------------------------------------------------------------------------
>> *From:* Eric Ehlers <eri...@re...>
>> <mailto:eri...@re...>
>> *Sent:* Monday, November 9, 2020, 11:42 PM
>> *To:* SX L
>> *Cc:* qua...@li...
>> <mailto:qua...@li...>
>> *Subject:* Re: [Quantlib-users] ObservableSettings is deleted early
>> than Observables.
>>
>> Hi Philip,
>>
>> I tried unsuccessfully to recreate the error. You did not say which
>> operating system you are using but you mention "debug version" which
>> sounds like visual studio so I tested it on Windows - I'm using
>> Visual Studio 2019 on 64-bit WIndows 10. I built it using "Debug
>> (static runtime)" x64 and I ran ClientCppDemo and it behaves as I
>> expected (no access violation). Anything else I can try to recreate
>> the error?
>>
>> I have not examined the code but your remarks sound sensible to me.
>> What resolution would you suggest?
>>
>> Regards,
>> Eric
>>
>> On 10/7/20 6:43 AM, SX L wrote:
>>> I was trying the Quantlib Addin. The QLADemo exits abnormally in the
>>> debug version with an access violation exception. It turned out to
>>> be the case that ObervableSettings is deleted earlier than some
>>> observer and observables at exit. So in the dtor of the observer,
>>> ObservableSettings is called to check if update is deferred, hence
>>> causing the exception. I feel it's unsafe to use shared pointers
>>> inside a singleton. Any suggestion? Thanks.
>>>
>>> Regards,
>>>
>>> Philip
>>>
>>>
>>> Get Outlook for Android <https://aka.ms/ghei36>
>>>
>>>
>>> _______________________________________________
>>> QuantLib-users mailing list
>>> Qua...@li... <mailto:Qua...@li...>
>>> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>>
|