|
From: Peter C. <pca...@gm...> - 2020-11-18 20:32:42
|
If we store a shared_ptr to ObservableSettings in Observable instead
of the reference, would that work? This would require an extension of
Singleton though.
On Tue, 17 Nov 2020 at 13:54, SX L <han...@ho...> wrote:
>
> Calling dtor != deleted. As long as nobody is trying to access the deleted instances, it should be fine. I agree the fix is not an ideal solution.
>
> ________________________________
> From: Peter Caspers <pca...@gm...>
> Sent: Monday, November 16, 2020 1:37 AM
> To: SX L <han...@ho...>
> Cc: Eric Ehlers <eri...@re...>; qua...@li... <qua...@li...>
> Subject: Re: [Quantlib-users] ObservableSettings is deleted early than Observables.
>
> That makes sense. But then, how does your proposed fix help in this
> situation? To me, it looks like the ObservableSettings instance might
> still get deleted before the observables?
>
> On Sun, 15 Nov 2020 at 16:30, SX L <han...@ho...> wrote:
> >
> > My guess is that the shared_ptr of those non-static Observables are stored in another static variable such as OH::Repository. So it depends on which dtor between the two static variables will be called first.
> >
> > ________________________________
> > From: Peter Caspers <pca...@gm...>
> > Sent: Saturday, November 14, 2020 8:08 PM
> > To: SX L <han...@ho...>
> > Cc: Eric Ehlers <eri...@re...>; qua...@li... <qua...@li...>
> > Subject: Re: [Quantlib-users] ObservableSettings is deleted early than Observables.
> >
> > Hi Philip, I am just curious and maybe the question is naive, but if
> > the ObservableSettings instance is stored as a
> > shared_ptr<ObservableSettings> within a static map, how can that
> > instance be destroyed before any non-static Observable instance?
> > Thanks, Peter
> >
> > On Sat, 14 Nov 2020 at 09:27, SX L <han...@ho...> 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
> > >
> > > ________________________________
> > > From: Eric Ehlers <eri...@re...>
> > > Sent: Monday, November 9, 2020, 11:42 PM
> > > To: SX L
> > > Cc: 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
> > >
> > >
> > > _______________________________________________
> > > QuantLib-users mailing list
> > > Qua...@li...
> > > https://lists.sourceforge.net/lists/listinfo/quantlib-users
> > >
> > >
> > > _______________________________________________
> > > QuantLib-users mailing list
> > > Qua...@li...
> > > https://lists.sourceforge.net/lists/listinfo/quantlib-users
|