Commit b4883edc authored by Jan Möbius's avatar Jan Möbius

Fixed crash when writing with multiple threads to mostream. closes #2293

Note: This fix requires C++11 support



git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1212 fdac6126-5c0c-442c-9429-916003d36597
parent 52d0ebba
......@@ -63,6 +63,10 @@
#include <string>
#include <algorithm>
#if __cplusplus > 199711L or __GXX_EXPERIMENTAL_CXX0X__
#include <mutex>
#endif
//== NAMESPACES ===============================================================
......@@ -177,6 +181,11 @@ protected:
// output what's in buffer_
virtual int sync()
{
// If working on multiple threads, we need to serialize the output correctly (requires c++11 headers)
#if __cplusplus > 199711L or __GXX_EXPERIMENTAL_CXX0X__
std::lock_guard<std::mutex> lck (serializer_);
#endif
if (!buffer_.empty())
{
if (enabled_) multiplex();
......@@ -196,7 +205,17 @@ protected:
int_type overflow(int_type _c = multiplex_streambuf::traits_type::eof())
{
char c = traits_type::to_char_type(_c);
buffer_.push_back(c);
// If working on multiple threads, we need to serialize the output correctly (requires c++11 headers)
#if __cplusplus > 199711L or __GXX_EXPERIMENTAL_CXX0X__
{
std::lock_guard<std::mutex> lck (serializer_);
buffer_.push_back(c);
}
#else
buffer_.push_back(c);
#endif
if (c == '\n') sync();
return 0;
}
......@@ -236,6 +255,12 @@ private:
target_map target_map_;
std::string buffer_;
bool enabled_;
// If working on multiple threads, we need to serialize the output correctly (requires c++11 headers)
#if __cplusplus > 199711L or __GXX_EXPERIMENTAL_CXX0X__
std::mutex serializer_;
#endif
};
#undef STREAMBUF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment