You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Supplement statements with references to C11 and LLVM docs
References to C11 standard were added when explaining properties of
atomic type and operations. More information of codegen on atomic
operations is added as a footnote with a link to LLVM's document as an
example.
Copy file name to clipboardExpand all lines: concurrency-primer.tex
+12-4Lines changed: 12 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -321,8 +321,14 @@ \section{Enforcing law and order}
321
321
This model, defined by Leslie Lamport in 1979,
322
322
is called \introduce{sequential consistency}.
323
323
324
-
Notice that using atomic variables as an lvalue expression, such as \monobox{v\_ready = true} and \monobox{while(!v\_ready)}, is a convenient alternative to explicitly using \monobox{atomic\_load} or \monobox{atomic\_store}.
325
-
Lvalue-to-rvalue conversion (which models a memory read from an atomic location to a CPU register) strips atomicity along with other qualifiers.
324
+
Notice that using atomic variables as an lvalue expression, such as \monobox{v\_ready = true} and \monobox{while(!v\_ready)}, is a convenient alternative to explicitly using \monobox{atomic\_load} or \monobox{atomic\_store}.\punckern\footnote{%
325
+
Atomic load/store are not necessary generated as atomic instructions.
326
+
Under a weaker consistency model, they could simply be normal load/store,
327
+
and their code generation can vary across different architectures.
328
+
Checkout \href{https://llvm.org/docs/Atomics.html\#atomics-and-codegen}{LLVM's document} as an example to see how it is handled.}
329
+
As stated in C11 6.7.2.4 and 6.7.3, the properties associated with atomic types are meaningful only for expressions that are
330
+
lvalues.
331
+
Lvalue-to-rvalue conversion (which models a memory read from an atomic location to a CPU register) strips atomicity along with other qualifiers.
326
332
327
333
\section{Atomicity}
328
334
\label{atomicity}
@@ -465,7 +471,7 @@ \subsection{Compare and swap}
465
471
Finally, we have \introduce{compare-and-swap} (\textsc{CAS}),
466
472
sometimes called \introduce{compare-and-exchange}.
467
473
It allows us to conditionally exchange a value \emph{if} its previous value matches the expected one.
468
-
In \clang{} and \cplusplus{}, \textsc{CAS} resembles the following,
474
+
In \clang{} and \cplusplus{}, as noted in C11 7.17.7.4, \textsc{CAS} resembles the following,
469
475
if it were executed atomically:
470
476
\begin{ccode}
471
477
/* A is an atomic type. C is the non-atomic type corresponding to A */
@@ -952,7 +958,9 @@ \subsection{Relaxed}
952
958
if (job->args == NULL) {
953
959
atomic_store(&thrd_pool->state, idle);
954
960
} else {
955
-
printf("Hello from job %d\n", *(int *)job->args);
961
+
void *ret_value = job->func(job->args);
962
+
job->future->result = ret_value;
963
+
atomic_flag_clear(&job->future->flag);
956
964
free(job->args);
957
965
free(job); // could cause dangling pointer in other threads
0 commit comments