Menu

Is slog thread-safe?

Help
2001-09-04
2001-09-05
  • Olleg Samoylov

    Olleg Samoylov - 2001-09-04

    Header file slog.h very slightly commented. I have looked into source file. As I undestood, Slog must be used as:

    // Without constructor, using external Slog slog
    slog.open("MyProgram",class_t);
    slog(level,class_t)<<"My error"<<endl;
    // Redefined operator () and <<
    slog.close();

    In ChangeLog said for version 1.3.0: "slog now uses thread-safe buffering to assume consistency".

    But when I looked in source from cvs of version 1.5.1, I couldn't see thread-safe measures between slog.open(...), slog(...),slog<<.

    Is it means, that I must create Slog instance for every thread and don't use external variable slog?

     
    • David Sugar

      David Sugar - 2001-09-05

      slog uses a getThread method to aquire a buffer.  This assures each thread writing a slog is doing so in a threadsafe and seperate buffer area.  A single open is needed because the same syslog handle is used by all threads.  They each collect in a seperate per-thread memory buffer and then flush the log directly in a single atomic write operation.

       
    • Olleg Samoylov

      Olleg Samoylov - 2001-09-05

      slog uses the thread-safe buffer, which get from getThread (it is member of Thread) only in method overflow(int). As I can undestand, this is measure to prevent mix text of messages from each thread.
      But attributes of messages (such as 'level' and 'class', which setted by slog(level,class) and etc) aren't placed in thread buffer, so such attributes can be mixed between messages from different threads.
      Am I correct undestanding?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.