Skip to content

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

Merged
merged 11 commits into from
Aug 1, 2024

Conversation

idoleat
Copy link
Collaborator

@idoleat idoleat commented Jun 16, 2024

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.

@jserv jserv requested a review from weihsinyeh June 26, 2024 09:43
Copy link
Contributor

@jserv jserv left a 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.

idoleat added 5 commits July 23, 2024 21:52
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}
Copy link
Contributor

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.

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.
Copy link
Contributor

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.
Copy link
Contributor

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?

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.
Copy link
Contributor

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.

idoleat added 3 commits July 26, 2024 17:28
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.
@jserv jserv merged commit 68dae00 into sysprog21:main Aug 1, 2024
@jserv
Copy link
Contributor

jserv commented Aug 1, 2024

Thank @idoleat for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants