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

Potential Bug #3

Open
xingyuuchen opened this issue Oct 19, 2023 · 0 comments
Open

Potential Bug #3

xingyuuchen opened this issue Oct 19, 2023 · 0 comments

Comments

@xingyuuchen
Copy link

xingyuuchen commented Oct 19, 2023

Hello, first thanks for your amazing work!

I found here may be a potential bug:

First you tried to lock the bucket:
if (bucket.state.compare_exchange_strong(bucketState, Bucket::State::BUSY, std::memory_order_relaxed))
Then you write key (and value) in:
bucket.entry.first = std::move(key);
Finally your change the state of the bucket to mark its state as ready:
bucket.state.store(Bucket::State::VALID, std::memory_order_release); // mark the bucket as valid

The problem, I think, lies in the situation when two threads try to insert the same key into the hashtable:
The two threads can probably insert the same key into two different buckets - when one thread already applied a free bucket but hasn't saved the key inside. At this time, the second thread cannot see the key in the table so it would apply a new bucket for that key.

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