3D City v-1.0
Computer Graphics Project
synced_stream Class Reference

A helper class to synchronize printing to an output stream by different threads. More...

#include <thread_pool.hpp>

Public Member Functions

 synced_stream (std::ostream &_out_stream=std::cout)
 Construct a new synced stream. More...
 
template<typename... T>
void print (const T &...items)
 Print any number of items into the output stream. More...
 
template<typename... T>
void println (const T &...items)
 Print any number of items into the output stream, followed by a newline character. More...
 

Private Attributes

std::mutex stream_mutex = {}
 A mutex to synchronize printing. More...
 
std::ostream & out_stream
 The output stream to print to. More...
 

Detailed Description

A helper class to synchronize printing to an output stream by different threads.

Definition at line 393 of file thread_pool.hpp.

Constructor & Destructor Documentation

◆ synced_stream()

synced_stream::synced_stream ( std::ostream &  _out_stream = std::cout)
inline

Construct a new synced stream.

Parameters
_out_streamThe output stream to print to. The default value is std::cout.

Definition at line 400 of file thread_pool.hpp.

Member Function Documentation

◆ print()

template<typename... T>
void synced_stream::print ( const T &...  items)
inline

Print any number of items into the output stream.

Ensures that no other threads print to this stream simultaneously, as long as they all exclusively use this synced_stream object to print.

Template Parameters
TThe types of the items
Parameters
itemsThe items to print.

Definition at line 410 of file thread_pool.hpp.

◆ println()

template<typename... T>
void synced_stream::println ( const T &...  items)
inline

Print any number of items into the output stream, followed by a newline character.

Ensures that no other threads print to this stream simultaneously, as long as they all exclusively use this synced_stream object to print.

Template Parameters
TThe types of the items
Parameters
itemsThe items to print.

Definition at line 422 of file thread_pool.hpp.

Member Data Documentation

◆ out_stream

std::ostream& synced_stream::out_stream
private

The output stream to print to.

Definition at line 435 of file thread_pool.hpp.

◆ stream_mutex

std::mutex synced_stream::stream_mutex = {}
mutableprivate

A mutex to synchronize printing.

Definition at line 430 of file thread_pool.hpp.