-
Notifications
You must be signed in to change notification settings - Fork 26
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
Expose asymmetric_light_barrier
and add a document
#56
base: main
Are you sure you want to change the base?
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.
Hi there! Thanks for taking the time to write this up — this is some great documentation to have, and I agree with your rationale for making this function public!
Just one note about a nuance of the doc, and then I'm happy with it 👍
/// To ensure safety, users need to appropriately synchronize the write operation on a hazard | ||
/// slot and validate that the pointer hasn't already been retired. For synchronization, the | ||
/// library offers an [`asymmetric_light_barrier`] function. It enables reclaiming threads | ||
/// to acknowledge the preceding protection. |
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 wording here is a little imprecise for my taste. The current phrasing makes it seem like an acknowledgement is somehow "sent" via a call to asymmetric_light_barrier
, but that's not really what happens. My understanding is that the barrier specifically has two side-effects:
- That the
load_ptr
onhead
happens strictly after the call toprotect_raw
- That if another thread exchanges
head
, and that exchange is not observed by this thread, then theprotect_raw
must be visible to that other thread (since the exchange must have happened-after ourload_ptr
, which happened after ourprotect_raw
).
I think it would be good to capture some of that nuance here and/or in the docs for asymmetric_light_barrier
.
What do you think?
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.
Thank you for reviewing, and I am sorry for the late reply. 😅
I agree with your point. The current explanation might mislead readers that asymmetric_light_barrier
alone somehow prevents reclaimers from freeing the object, which is not true. I think that I have omitted too many details.
The relationship between barriers and validation should be described more clearly.
The main idea that must be expressed would be that asymmetric_light_barrier
makes essential happens-before relations to hold. For example, if I model the entire system of Hazard pointers like the following...
procedure Protect(p):
P1. Announce protection of p.
P2. Issue a **light** barrier.
P3. Check if p is not retired. If retired, must retry after reloading the pointer.
procedure Reclaim(p):
R1. Announce retirement of p.
R2. Issue a **heavy** barrier.
R3. Check if p is protected. If protected, retry later.
The semantics of the light and heavy barrier are (->
is happens-before relation):
- If
P2 -> R2
,P1 -> R3
(the protection ofP1
is visible toR3
). - If
R2 -> P2
,R1 -> P3
(the retirement ofR1
is visible toP3
). P2
ensuresP1 -> P2 -> P3
andR2
ensuresR1 -> R2 -> R3
.
These three lemmas cover the two points you mentioned. With these lemmas, we can show that:
- If
P2
happens beforeR2
, the reclaimer will not freep
. - If
R2
happens beforeP2
, the accessor will not accessp
.
In either case, use-after-free errors do not occur.
So far, this is what I'm going to describe in a revised version. Please feel free to give comments if you want.
I think I'd be able to push a revised version this week. After the work, I would be happy if you review my PR again!
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.
Yes, that looks really good, thanks for diving so deep into it!
Codecov Report
Additional details and impacted files
|
It fixes #55.