Skip to content

Commit

Permalink
Make ConsoleStream thread-safe
Browse files Browse the repository at this point in the history
Use the same mutex for both `operator<<` overloads. Refs CIVET
failure https://civet.inl.gov/job/2295949/ on libMesh/libmesh#3883
  • Loading branch information
lindsayad committed Jun 26, 2024
1 parent d964da4 commit 4246007
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions framework/include/outputs/ConsoleStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,10 @@ class ConsoleStream
/// of something in AutomaticMortarGeneration that requires
/// this to be trivially copyable.
mutable std::shared_ptr<std::ostringstream> _oss;
};

extern std::mutex _stream_mutex;
/// Mutex to prevent concurrent read/writes, write/writes
static std::mutex _stream_mutex;
};

template <typename StreamType>
const ConsoleStream &
Expand Down
6 changes: 2 additions & 4 deletions framework/src/outputs/ConsoleStream.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
#include "MooseUtils.h"
#include "OutputWarehouse.h"

std::mutex _stream_mutex;
std::mutex ConsoleStream::_stream_mutex;

ConsoleStream::ConsoleStream(OutputWarehouse & output_warehouse)
: _output_warehouse(output_warehouse), _oss(std::make_shared<std::ostringstream>())
{
}

static std::mutex manip_mutex;

const ConsoleStream &
ConsoleStream::operator<<(const StandardEndLine & manip) const
{
const std::lock_guard<std::mutex> lock(manip_mutex);
const std::lock_guard<std::mutex> lock(_stream_mutex);

if (manip == (std::basic_ostream<char> & (*)(std::basic_ostream<char> &)) & std::endl)
(*_oss) << '\n';
Expand Down

0 comments on commit 4246007

Please sign in to comment.