Skip to content

Fix error of __list_find #8

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 1 commit into from
Aug 8, 2021
Merged

Fix error of __list_find #8

merged 1 commit into from
Aug 8, 2021

Conversation

RinHizakura
Copy link
Contributor

The node on the linked list should follow the ordering by its key. However, the function list_insert doesn't actually do this because of the wrong implementation of __list_find.

There are three main fixes in this patch. First, once we should do synchronization, we have to iterate the list again but not return from the function. Second, the while loop should iterate until the last node but not the second last one. Finally,
under the normal situation that the tail node with key UINTPTR_MAX should not be deleted (unless the end of the program), some codes are never executed which can be removed.

@jserv
Copy link
Contributor

jserv commented Aug 8, 2021

I would expect the following comments:

On a CAS failure, the search function, "__list_find", will simply have to
go backwards in the list until an unmarked element is found from which
he search in increasing key order can be started.

For the implementation to be correct, the predecessor pointers only
have to fulfill that any item always has a path back to the head of the
list. When a new item is inserted into the list, the predecessor pointer
of the successor is set with an atomic store to point to the new element.
Likewise, when an item is removed, the predecessor pointer of the
successor item is updated to skip the removed item. This suffices to
maintain the invariant, but through long sequences of concurrent
insertions and deletions, backwards pointers can become imprecise
in that they skip many items that are actually in the list.

My implementation was a functional rewriting of paper A more Pragmatic Implementation of the Lock-free, Ordered, Linked List. You can check its implementations and benchmark programs: lockfree-linked-list.

@RinHizakura RinHizakura force-pushed the pr branch 2 times, most recently from fbdb1ec to 1447f84 Compare August 8, 2021 17:18
@RinHizakura
Copy link
Contributor Author

Thanks for the information. I changed the comment according to yours.

The node on the linked list should follow the ordering by its key.
However, the function list_insert doesn't actually do this because
of the wrong implementation of __list_find.

There are three main fixes in this patch. First,
once we should do synchronization, we have to iterate the list
again but not return from the function. Second, the while loop should
iterate until the last node but not the second last one. Finally,
under the normal situation that the tail node with key UINTPTR_MAX should
not be deleted (unless the end of the program), some codes are never executed
which can be removed.
@jserv jserv merged commit 9fa5bf8 into sysprog21:master Aug 8, 2021
@RinHizakura RinHizakura deleted the pr branch August 11, 2021 14:30
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