Usually the whole point of a SharedArray is that workers only update the piece 
they "own." You can make it work different if you implement locking, but lock 
contention can be a bottleneck.

--Tim

On Monday, July 20, 2015 04:29:04 PM John Brock wrote:
> I'm seeing inconsistent results when multiple workers write values to a
> SharedArray at the same time, presumably because += isn't atomic. Is this
> intended behavior, and is there a workaround? Behavior is reproducible in
> 0.3.8-pre+22 and 0.3.9.
> 
> Sample code:
> 
> function doStuff()
>   result_shared = SharedArray(Int64, (2,), init = S -> S[localindexes(S)] =
> 0)
>   @sync for i=1:3
>     @spawn begin
>       result_shared[:] += [i, i]
>     end
>   end
>   return sdata(result_shared)
> end
> 
> > julia -p 3
> 
> julia> dump(doStuff())
> Array(Int64,(2,)) [3,3]
> 
> julia> dump(doStuff())
> Array(Int64,(2,)) [6,6]

Reply via email to