You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
julia> Threads.nthreads()
8
julia> using PooledArrays
julia> x = PooledArray(zeros(10^6));
julia> Threads.@threads for i in 1:10^6
x[i] = i
end
ERROR: TaskFailedException:
BoundsError: attempt to access 228263-element Array{Float64,1} at index [13310]
I think we should make setindex! thread safe. Any opinions?
The text was updated successfully, but these errors were encountered:
Like in CategoricalArrays, the problem is that even if we took a lock on each setindex! call, calling getindex in parallel wouldn't be thread-safe if a new level is added (as the pool may be resized). Yet taking a lock on getindex would kill performance.
Also, taking a lock on each setindex! call would make it impossible to run it in parallel, yet that's perfectly safe if you know that you don't add many levels. Not sure whether it's a typical case or not, but that happens e.g. if you reorder values in the array (e.g. sorting).
What we can do without affecting performance is take a lock when adding new levels. That should at least fix the example you give, and adding levels is relatively slow and can't be done in parallel anyway. But that doesn't provide a lot of safety either.
See the following example:
I think we should make
setindex!
thread safe. Any opinions?The text was updated successfully, but these errors were encountered: