bloom-filter-scala icon indicating copy to clipboard operation
bloom-filter-scala copied to clipboard

Is this bloom filter threadsafe?

Open LeifW opened this issue 4 years ago • 2 comments

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

LeifW avatar Jul 12 '21 19:07 LeifW

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.

https://github.com/alexandrnikitin/bloom-filter-scala/blob/b2c41c02f694529acbb3d22237d4a192b845d197/bloom-filter/src/main/scala/bloomfilter/mutable/UnsafeBitArray.scala#L19-L26

harpocrates avatar Jul 15 '21 15:07 harpocrates

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

rac021 avatar Apr 03 '23 02:04 rac021