Skip to content

Commit 72837c9

Browse files
hageboecksponce
authored andcommitted
Add a slide on osyncstream (cpp20).
1 parent 571b224 commit 72837c9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

talk/concurrency/mutexes.tex

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,25 @@
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}

0 commit comments

Comments
 (0)