Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Thread-safe singleton



  • I would like to hear your criticism about "this":http://developer.qt.nokia.com/wiki/Qt_thread-safe_singleton article.



  • I think that
    @static T& instance()@

    should become
    @static const T& instance()@

    UPD: And i think that you need to explain in that article what do you need call_once for, since this is a wiki page.



  • Why reference to T must be const, what if user want change internal state of class?

    call_once it's thread-safe alternative for Double-Checked Locking pattern.



  • [quote author="SABROG" date="1282146241"]Why reference to T must be const, what if user want change internal state of class?[/quote]

    Yep, you are right. My fault.

    [quote author="SABROG" date="1282146241"]call_once it's thread-safe alternative for Double-Checked Locking pattern.[/quote]

    I read about it :). What I meant is towrite just a few words of description on that page, so there is not just naked code.


Log in to reply