rm5248 commented on code in PR #148:
URL: https://github.com/apache/logging-log4cxx/pull/148#discussion_r1015347242


##########
src/main/cpp/messagebuffer.cpp:
##########
@@ -149,10 +118,14 @@ CharMessageBuffer& CharMessageBuffer::operator<<(const 
char msg)
 
 CharMessageBuffer::operator std::basic_ostream<char>& ()
 {
-       if (m_priv->stream == 0)
+       if (!m_priv->stream)
        {
+#if LOG4CXX_HAS_THREAD_LOCAL
+               thread_local static std::basic_ostringstream<char> sStream;
+               m_priv->stream = &sStream;
+#else
                m_priv->stream = new std::basic_ostringstream<char>();
-
+#endif

Review Comment:
   At this point I'm not aware of any compiler that supports C++11 but not 
`thread_local`, would it make sense to simply make `m_priv->stream` a 
`thread_local` variable instead of holding a pointer?  I could be wrong here, 
but it looks like if two threads are logging at the same time they could both 
get the same `ostringstream`, thus defeating the purpose of the `thread_local`. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to