vigna / fastutil

fastutil extends the Java™ Collections Framework by providing type-specific maps, sets, lists and queues.
Apache License 2.0
1.81k stars 199 forks source link

Thread-safety of *BigArrayBigList #297

Closed progval closed 1 year ago

progval commented 1 year ago

Apologies if this is already documented somewhere, but I couldn't find it.

What are the thread safety guarantees of the various *BigArrayBigList classes? I noticed that appending to it from multiple threads drops values (which is understandable given the absence of locks).

In particular, I am interested in the case where I'm setting values within a BigArrayBigList that is already allocated and doesn't get larger.

Thanks!

vigna commented 1 year ago

They are not documented because there are none :). You must wrap everything into a synchronized wrapper if you need thread safety.

Of course you can read in parallel safely. That should be probably documented.

Setting in parallel will leave you with race conditions. If you wanna to that, you're better of with a AtomicInteger big array as managed by BigArrays/IntBigArrays.