bloom-filter-scala
bloom-filter-scala copied to clipboard
Is this bloom filter threadsafe?
That is, is calling .add and .mightContain concurrently from many different threads going to work?
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
Will there be a thread-safe implementation of this Bloom filter ?