I've been running into issues with WignerSymbols.jl, where one of the necessary operations is calculating the prime factorization of certain numbers. To speed this up you'd want to cache any found prime factors, and this cache is exactly what makes it thread unsafe.
As far as I can tell, there are 2 options. Either work with a lock, but that would slow down the existing code, even in situations where it was already called in a threadsafe way. The other way would be to work with thread-local caches (someone tried this https://github.com/Jutho/WignerSymbols.jl/pull/13 but memory consumption gets out of hand).
Ideally you would have some array type, for which getindex is fast, and as long as this index is < length(array), it is garantueed to be threadsafe. Modifying the array is allowed to be slower (getting a lock or something). I think a normal array does not have this property, because push! may cause the entire array to be re-allocated somewhere.
I have a few questions :
is there a list of thread safe array operations?
what kind of caching mechanism should I go for?
can I make my "ideal" array type somehow?
Last updated: Nov 06 2024 at 04:40 UTC