@@ -318,7 +318,8 @@ \section{Enforcing law and order}
318
318
int v = 0;
319
319
atomic_bool v_ready = false;
320
320
321
- void *threadA() {
321
+ void *threadA()
322
+ {
322
323
v = 42;
323
324
v_ready = true;
324
325
}
@@ -328,7 +329,8 @@ \section{Enforcing law and order}
328
329
\begin {minted }[fontsize=\codesize ]{c}
329
330
int bv;
330
331
331
- void *threadB() {
332
+ void *threadB()
333
+ {
332
334
while(!v_ready) { /* wait */ }
333
335
bv = v;
334
336
/* Do something */
@@ -373,7 +375,7 @@ \section{Atomicity}
373
375
just make sure that any variables used for thread synchronization
374
376
are no larger than the \textsc {cpu} word size.
375
377
376
- \section {Arbitrarily-sized “ atomic” types }
378
+ \section {Arbitrarily-sized `` atomic'' types }
377
379
378
380
Along with \texttt {atomic\_ int } and friends,
379
381
\cplusplus {} provides the template \texttt {std::atomic<T> } for defining arbitrary atomic types.
@@ -398,8 +400,7 @@ \section{Arbitrarily-sized “atomic” types}
398
400
Consequently, \cplusplus {17} added \texttt {is\_ always\_ lock\_ free }:
399
401
\begin {colfigure }
400
402
\begin {minted }[fontsize=\codesize ]{cpp}
401
- static_assert(
402
- std::atomic<Foo>::is_always_lock_free);
403
+ static_assert(std::atomic<Foo>::is_always_lock_free);
403
404
\end {minted }
404
405
\end {colfigure }
405
406
@@ -453,10 +454,10 @@ \subsection{Test and set}
453
454
void unlock() { atomic_flag_clear(&af); }
454
455
\end {minted }
455
456
\end {colfigure }
456
- If we call \mintinline {cpp }{lock()} and the previous value is \mintinline {cpp }{false},
457
+ If we call \mintinline {c }{lock()} and the previous value is \mintinline {c }{false},
457
458
we are the first to acquire the lock,
458
459
and can proceed with exclusive access to whatever the lock protects.
459
- If the previous value is \mintinline {cpp }{true},
460
+ If the previous value is \mintinline {c }{true},
460
461
someone else has acquired the lock and we must wait until they release it by clearing the flag.
461
462
462
463
\subsection {Fetch and… }
@@ -636,7 +637,7 @@ \section{Sequential consistency on weakly-ordered hardware}
636
637
\begin {minted }[fontsize=\codesize ]{cpp}
637
638
void setFoo(int i)
638
639
{
639
- foo = i;
640
+ foo = i;
640
641
}
641
642
\end {minted }
642
643
\end {minipage }
@@ -1344,7 +1345,7 @@ \section{Additional Resources}
1344
1345
\textsc {n}4455}, and as a
1345
1346
\href {https://www.youtube.com/watch?v=IB57wIf9W1k}{CppCon talk}.
1346
1347
1347
- \href {http ://en.cppreference.com}{cppreference.com},
1348
+ \href {https ://en.cppreference.com}{cppreference.com},
1348
1349
an excellent reference for the \clang {} and \cplusplus {} memory model and atomic \textsc {api}.
1349
1350
1350
1351
\href {https://godbolt.org/}{Matt Godbolt's Compiler Explorer},
0 commit comments