File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 225225 \end {cppcode* }
226226 \end {exampleblock }
227227\end {frame }
228+
229+ \begin {frame }[fragile]
230+ \frametitlecpp [20]{Synchronised \texttt {cout }}
231+ \begin {block }{Parallel writing to streams}
232+ \begin {itemize }
233+ \item All parallel writes to streams become garbled when not synchronised
234+ \item \cppinline {std::osyncstream} is a wrapper to synchronise output to streams
235+ \item Multiple instances of the osyncstream synchronise globally
236+ \end {itemize }
237+ \end {block }
238+ \begin {exampleblock }{}
239+ \begin {cppcode* }{gobble=2}
240+ void worker(const int id, std::ostream & os);
241+ void func() {
242+ std::osyncstream synccout1{std::cout};
243+ std::osyncstream synccout2{std::cout};
244+ std::jthread t1{worker, 0, std::ref(synccout1)};
245+ std::jthread t2{worker, 1, std::ref(synccout2)};
246+ }
247+ \end {cppcode* }
248+ \end {exampleblock }
249+ \end {frame }
You can’t perform that action at this time.
0 commit comments