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
Copy file name to clipboardExpand all lines: concurrency-primer.tex
+23Lines changed: 23 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -883,6 +883,29 @@ \subsection{Conclusion about lock-free}
883
883
Balancing complexity and performance is essential in concurrency,
884
884
a domain fraught with challenges.
885
885
886
+
\subsection{ABA problem}
887
+
We have introduced CAS as one of the read-modify-write operations.
888
+
However, does the target object not changing really mean that no other threads modified it halfway through?
889
+
Consider the following scenario,
890
+
891
+
\begin{ccode}
892
+
/* example code place holder */
893
+
do { /* read and modify */ }
894
+
/* something can happen in between */
895
+
while(CAS);
896
+
\end{ccode}
897
+
898
+
If the target object is changed to something by other thread and changed back, the result of comparism is still equal.
899
+
Although the target object has indeed been changed, causing the operation to not remain atomic.
900
+
We call this \introduce{ABA problem}. In the example above, the presents of ABA problem leads to
901
+
902
+
The ABA problem occurs when changes occur between reading and comparing, but the comparing mechanism is unable to identify that the state is not the latest.
903
+
The maximum number we refer to may not be the actual maximum, and the next job may not be the same job.
904
+
Failure to recognize this through comparison can result in outdated information.
905
+
The general concept of solving this problem involves adding more information to make different state distinguishable, and then making a decision on whether to act on the old state or retry with the new state.
906
+
If acting on the old state is chosen, then safe memory reclamation should be considered as memory may have already been freed by other threads.
907
+
More aggressively, one might consider the programming paradigm where each operation on the target object does not have a side effect on modifying it.
908
+
886
909
\section{Sequential consistency on weakly-ordered hardware}
887
910
888
911
Different hardware architectures offer distinct memory models or \introduce{memory models}.
0 commit comments