replace SML-level implementation of ABP deque with implementation in C #214
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This makes it possible to use the appropriate memory order annotations, to ensure correct compilation on weakly ordered architectures such as ARM.
AFAICT, this fixes #212. On a MacBook Air M2 (2022) I'm no longer seeing these errors in my tests.
I used memory ordering annotations inspired by the ParlayLib implementation:
https://github.com/cmuparlay/parlaylib/blob/36459f42a84207330eae706c47e6fab712e6a149/include/parlay/internal/work_stealing_deque.h
One difference between our deque and the standard ABP deque is that we use the current top index of the deque to interface between the scheduler and the GC. For example, an empty deque with top=5 indicates that depths 1-4 are out of scope of LGC (because the corresponding tasks have been stolen). So, when our deque becomes empty, rather than reset the top/bottom indices to 0 (as a standard ABP deque would do), we instead keep them set at the current value.
I believe this patch may also fix another subtle bug related to the deque, specifically the tag of the packed tag+idx not being advanced here:
mpl/basis-library/schedulers/shh/queue/DequeABP.sml
Lines 223 to 230 in 70bfe0f
I don't have any evidence of a failing test or otherwise, but it seems like it can cause an ABA problem, if another concurrent steal were in-flight at the same index but then managed to succeed later with the same top tag. This patch correctly advances the top tag in this case:
https://github.com/shwestrick/mpl/blob/f6d02f4025ba5df0c2cac533c85db52e68f3dfba/runtime/gc/abp-deque.c#L72-L80