libyui
Public Member Functions | Public Attributes

YPerThreadLogInfo Struct Reference

List of all members.

Public Member Functions

 YPerThreadLogInfo ()
 ~YPerThreadLogInfo ()
bool isThread (pthread_t otherThreadHandle)

Public Attributes

pthread_t threadHandle
YUILogBuffer logBuffer
ostream logStream

Detailed Description

Helper class: Per-thread logging information.

Multiple threads can easily clobber each others' half-done logging. A naive approach to prevent this would be to lock a mutex when a thread starts logging and unlock it when it's done logging. But that "when it's done" condition might never come true. std::endl or a newline in the output stream would be one indication, but there is no way to make sure there always is such a delimiter. If it is forgotten and that thread (that still has the mutex locked) runs into a waiting condition itself (e.g., UI thread synchronization with pipes), there would be a deadlock.

So this much safer approach was chosen: Give each thread its own logging infrastructure, i.e., its own log stream and its own log buffer.

Sure, in bad cases the logger function might still be executed in parallel and thus clobber a line or two of log output. But that's merely bad output formatting, not writing another thread's data structures without control - which can easily happen if multiple threads are working on the same output buffer, i.e. manipulate the same string.


Constructor & Destructor Documentation

YPerThreadLogInfo::YPerThreadLogInfo ( ) [inline]

Constructor

YPerThreadLogInfo::~YPerThreadLogInfo ( ) [inline]

Destructor


Member Function Documentation

bool YPerThreadLogInfo::isThread ( pthread_t  otherThreadHandle) [inline]

Check if this per-thread logging information belongs to the specified thread.


The documentation for this struct was generated from the following file:
 All Classes Functions Variables Enumerations Friends