A utility class to synchronize printing to an output stream by different threads.
More...
#include <BS_thread_pool_utils.hpp>
|
| synced_stream (std::ostream &stream=std::cout) |
| Construct a new synced stream.
|
|
| synced_stream (const synced_stream &)=delete |
|
| synced_stream (synced_stream &&)=delete |
|
synced_stream & | operator= (const synced_stream &)=delete |
|
synced_stream & | operator= (synced_stream &&)=delete |
|
template<typename... T> |
void | print (T &&... items) |
| 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 the same synced_stream object to print.
|
|
template<typename... T> |
void | println (T &&... items) |
| 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 the same synced_stream object to print.
|
|
|
static std::ostream &(&) | endl (std::ostream &) = static_cast<std::ostream& (&)(std::ostream&)>(std::endl) |
| A stream manipulator to pass to a synced_stream (an explicit cast of std::endl ). Prints a newline character to the stream, and then flushes it. Should only be used if flushing is desired, otherwise a newline character should be used instead.
|
|
static std::ostream &(&) | flush (std::ostream &) = static_cast<std::ostream& (&)(std::ostream&)>(std::flush) |
| A stream manipulator to pass to a synced_stream (an explicit cast of std::flush ). Used to flush the stream.
|
|
|
std::ostream & | out_stream |
| The output stream to print to.
|
|
std::mutex | stream_mutex = {} |
| A mutex to synchronize printing.
|
|
A utility class to synchronize printing to an output stream by different threads.
◆ synced_stream()
BS::synced_stream::synced_stream |
( |
std::ostream & |
stream = std::cout | ) |
|
|
inlineexplicit |
Construct a new synced stream.
- Parameters
-
stream | The output stream to print to. The default value is std::cout . |
std::ostream & out_stream
The output stream to print to.
Definition BS_thread_pool_utils.hpp:136
◆ print()
template<typename... T>
void BS::synced_stream::print |
( |
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 the same synced_stream
object to print.
- Template Parameters
-
- Parameters
-
105 {
107 (
out_stream << ... << std::forward<T>(items));
108 }
std::mutex stream_mutex
A mutex to synchronize printing.
Definition BS_thread_pool_utils.hpp:141
◆ println()
template<typename... T>
void BS::synced_stream::println |
( |
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 the same synced_stream
object to print.
- Template Parameters
-
- Parameters
-
118 {
119 print(std::forward<T>(items)...,
'\n');
120 }
void print(T &&... items)
Print any number of items into the output stream. Ensures that no other threads print to this stream ...
Definition BS_thread_pool_utils.hpp:104
◆ stream_mutex
std::mutex BS::synced_stream::stream_mutex = {} |
|
mutableprivate |
A mutex to synchronize printing.
The documentation for this class was generated from the following file: