Skip to content

Commit f35f108

Browse files
committed
Note -latomic needed when using -mcx16
The ABA example relies on 16-byte atomic compare-and-swap operations, which require the `-mcx16` compiler flag on x86-64 to enable the corresponding instructions. However, due to current limitations in GCC, 16-byte atomic operations (e.g., `__atomic_load_16` and `__atomic_compare_exchange_16`) are implemented via calls to `libatomic` on many platforms. This results in linker errors unless `-latomic` is explicitly added. To avoid confusion and ensure portability, this patch adds a footnote to the LaTeX document explaining that `-latomic` must be linked when using `-mcx16`. For more details, see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688
1 parent 68dae00 commit f35f108

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

concurrency-primer.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ \subsection{ABA problem}
959959
On x86-64 processors, for atomic instructions that load or store more than a CPU word size, it needs additional hardware support.
960960
You can use \monobox{grep cx16 /proc/cpuinfo} to check if the processor supports 16-byte compare-and-swap.
961961
For hardware that does not support the desired size, software implementations which may have locks involve are used instead, as mentioned in \secref{atomictype}.
962-
Back to the example, ABA problem in the following code is fixed by using an version number that increments each time a job is added to the empty queue. On x86-64, add a compiler flag \monobox{-mcx16} to enable 16-byte compare-and-swap in \monobox{worker} function.
962+
Back to the example, ABA problem in the following code is fixed by using an version number that increments each time a job is added to the empty queue. On x86-64, add a compiler flag \monobox{-mcx16} to enable 16-byte compare-and-swap in \monobox{worker} function.\footnote{When using \texttt{-mcx16}, programs relying on 16-byte atomic operations (e.g., using \texttt{\_\_int128}) may require linking with \texttt{-latomic}, as these operations are implemented via function calls to \texttt{libatomic} on some systems. See \url{https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104688}.}
963963

964964
\inputminted{c}{./examples/rmw_example_aba.c}
965965

0 commit comments

Comments
 (0)