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

Is this bloom filter threadsafe? #56

Open
LeifW opened this issue Jul 12, 2021 · 2 comments
Open

Is this bloom filter threadsafe? #56

LeifW opened this issue Jul 12, 2021 · 2 comments

Comments

@LeifW
Copy link

LeifW commented Jul 12, 2021

That is, is calling .add and .mightContain concurrently from many different threads going to work?

@harpocrates
Copy link

I wrote a short program to try to find incorrect behavior in the presence of multiple threads, and it unfortunately appears to find some. I think that counts as a witness proof that the bloom filter is not thread-safe.

Looking at the implementation: the backing array would need to use atomic operations like getAndBitWiseOr or else do some locking, but it does neither. It looks like the Java 9 VarHandle API would make this all very possible and efficient using ByteBuffer's, but I've got no idea how to do that without dropping Java 8 support.

def set(index: Long): Unit = {
val offset = ptr + (index >>> 6) * 8L
val long = unsafe.getLong(offset)
if ((long & (1L << index)) == 0) {
unsafe.putLong(offset, long | (1L << index))
bitCount += 1
}
}

@rac021
Copy link

rac021 commented Apr 3, 2023

Will there be a thread-safe implementation of this Bloom filter ?

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

3 participants