Skip to content

Commit 4dc5699

Browse files
committed
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.
1 parent a6c68a9 commit 4dc5699

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

concurrency-primer.tex

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,14 @@ \section{Enforcing law and order}
321321
This model, defined by Leslie Lamport in 1979,
322322
is called \introduce{sequential consistency}.
323323

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.
326332

327333
\section{Atomicity}
328334
\label{atomicity}
@@ -465,7 +471,7 @@ \subsection{Compare and swap}
465471
Finally, we have \introduce{compare-and-swap} (\textsc{CAS}),
466472
sometimes called \introduce{compare-and-exchange}.
467473
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,
469475
if it were executed atomically:
470476
\begin{ccode}
471477
/* A is an atomic type. C is the non-atomic type corresponding to A */
@@ -952,7 +958,9 @@ \subsection{Relaxed}
952958
if (job->args == NULL) {
953959
atomic_store(&thrd_pool->state, idle);
954960
} 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);
956964
free(job->args);
957965
free(job); // could cause dangling pointer in other threads
958966
}

0 commit comments

Comments
 (0)