Skip to content
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

Race condition on InsertPairUnique can result in duplicates of the same key #27

Open
huntermBerkeley opened this issue May 31, 2024 · 0 comments

Comments

@huntermBerkeley
Copy link

There is a race condition in the table when insertions and deletions occur concurrently.

This occurs when multiple unique insertions of the same key have a deletion interleaved between them, resulting in the inserting warps disagreeing on the correct position for insertion.

For a simple walkthrough consider a bucket currently storing one key A in slot 0, so the bucket is [A,empty].

Thread one is inserting key B and observes the bucket as [A,empty]. From this it determines slot 1 is the correct slot for insertion.

A different thread deletes A and frees slot 0, resulting in [empty, empty].

A third thread also inserts B. It observes the bucket as [empty, empty] and determines slot 0 as the correct slot.

Finally, both threads sucessfully CAS with empty_pair_64 and insert their keys. Neither thread observed the operation of the other but the final result in the bucket is [B,B] which is disallowed by insertPairUnique.

This also appears to be an issue if a key exists later in the chain, as the insertion will proceed if an empty slot exists in previous buckets in the chain despite a duplicate existing. Is this the expected behavior?

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

No branches or pull requests

1 participant