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
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -905,7 +905,7 @@ \subsection{ABA problem}
905
905
906
906
In the example provided, the presence of ABA problem results in thread A being unaware that variable \monobox{v} has been altered.
907
907
Since the comparison result indicates \monobox{v} unchanged, \monobox{v + 10} is swapped in.
908
-
Here sleeping is only used to ensure the occurance of ABA problem.
908
+
Here sleeping is only used to ensure the occurrence of ABA problem.
909
909
In real world scenario, instead of sleeping, thread A could paused by being context switched for other tasks, including being preempted by higher priority tasks.
910
910
This example seems harmless, but things can get nasty when atomic \textsc{RMW} operations are used in more complex data structures.
911
911
@@ -928,9 +928,9 @@ \subsection{ABA problem}
928
928
\item Thread A is preempted.
929
929
\item Thread B claims the job and successfully updates \monobox{thrd\_pool->head->prev}.
930
930
\item Thread B sets thread pool state to idle.
931
-
\item Main thread fininshes waiting and adds more jobs.
931
+
\item Main thread finishes waiting and adds more jobs.
932
932
\item Memory allocator reuses the recently freed memory as new jobs addresses.
933
-
\item Fortunately, the first added job has the same address as the one thread A holded.
933
+
\item Fortunately, the first added job has the same address as the one thread A held.
934
934
\item Thread A is back in running state. The comparison result is equal so it updates \monobox{thrd\_pool->head->prev} with the old \monobox{job->prev}, which is already a dangling pointer.
935
935
\item Another thread loads the dangling pointer from \monobox{thrd\_pool->head->prev}.
936
936
\end{enumerate}
@@ -963,7 +963,7 @@ \subsection{ABA problem}
963
963
\inputminted{c}{./examples/rmw_example_aba.c}
964
964
965
965
Notice that, in the \monobox{struct idle\_job}, a union is used for type punning, which bundles the pointer and version number for compare-and-swap.
966
-
Directly casting a job pointer to a pointer that points to a 16-byte object is undefined behavior (due to having different alignment), thus type punnined is used instead.
966
+
Directly casting a job pointer to a pointer that points to a 16-byte object is undefined behavior (due to having different alignment), thus type punning is used instead.
967
967
By using this techniques, \monobox{struct idle\_job} still can be accessed normally in other places, minimizing code modification.
968
968
Compiler optimizations are conservative on type punning, but it is acceptable for atomic operations.
0 commit comments