c++ - Thread-safe Logger object using the singleton pattern -


I must apply a logger for an application and I should use the singleton pattern. In addition, since this application is multithread, this logger should be thread-protected. I want to say that I have to use C ++ 03 .

I have seen using a QMutex still object in C ++ / QT to guarantee that only one thread allocates a unique example of singleton object.

Why does everyone return a button as an indicator? I will return it as a reference, so I should not worry about releasing the memory used by a single object clearly. I read and I wrote the following implementation.

  // ========== Include Logger.h # & lt; QMutex & gt; # Include & lt; QString & gt; Class logger {public: steady logger & amp; Examples (); Zero Configure (Constest & Folder); Private: logger (); Logger (consort logger & amp;); Logger & amp; Operator = (Constellor & amp;;); Private: Incorrect QMutex _mutex; Caststring _ folder; }; // ========== Logger.cpp Logger :: Logger (): _mutex () {; } Logger & amp; Logger :: Example () {Fixed QMutex mutex; Mutex.lock (); Static logger example; Mutex.unlock (); Return example; } Zero Logger :: Configurable (Cast Customs and Folders) {_mutex.lock (); _ Folder = folder; _mutex.unlock (); }  

I have some questions ...

  1. The function example () is created when unique example is thread-safe is?
  2. At the time of the destruction of an object, will the singleton object be destroyed in a secure way?


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -