-
Notifications
You must be signed in to change notification settings - Fork 15
Add ABA problem subsection in "Atomic operations as building blocks" #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase the latest main
branch.
First describing what can go wrong and then explain the root cause of it. Example code will be added later on as well as sultions to ABA problem.
Because ABA problem is not so intuitive, the plan is to have a simple example first, then reusing the new example in section 5. A nother stack example by "null program" will be mentioned for additional examples. Next commit will provide solutions to fix ABA problem in both examples.
Approaches are explained first, then the code and explanations on changes.
The new thread pool is ported to the rmw_example_aba.c file. Makefile is updated accordingly as well.
The compile command is added in the Makefile, same as the previous example code. Missing reference and wrong compiler flag are fixed as well.
|
||
The execution result would be: | ||
|
||
\begin{ccode} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following is not code. Instead, it is plaintext. Don't annotate with code
.
concurrency-primer.tex
Outdated
A: v = 52 | ||
\end{ccode} | ||
|
||
In the example provided, the presence of ABA problem results in thread A being unaware that variable \monobox{v} has been altered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotate with \cc
rather than \monobox
.
In fact, pre-allocated memory should be used to achieve lock-free since \monobox{malloc} could have mutex involved in multi-threaded environment. | ||
|
||
Failure to recognize changed target object through comparison can result in stale information. | ||
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This statement was not clear as for the impact of ABA problem. Can you improve it?
concurrency-primer.tex
Outdated
It requires the compare-and-swap instruction to be capable of comparing a wider size at once. | ||
Sometimes, this is referred to as \introduce{double-width compare-and-swap}. | ||
On x86-64 processors, for atomic instructions that load or store more than a CPU word size, it needs additional hardware support. | ||
You can use \monobox{\$ grep cx16 /proc/cpuinfo} to check if the processor supports 16-byte compare-and-swap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't specify $
for shell commands.
Replace \monobox{} with \cc{} to properly apply the style to C code. Dollar sign removed for shell command.
Presents them as statements rather than questions.
Thank @idoleat for contributing! |
Root causes and an easy example are first provided, and followed by possible solutions. The thread pool example from #7 is reused as more complex example. Not sure if text description of the example is clear enough. If not, figures could then be added.
Currently the thread pool example that fixed the ABA problem looks fine but I am not fully sure if the problem is really fixed. I will try model checking or formal proofing tools to verify that. If it goes well, it may be added as another section on verifying correctness of concurrent programs.