# Locking properties of AbstractArrays

**URL:** <https://discourse.julialang.org/t/locking-properties-of-abstractarrays/4141>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 7, 2017, 3:27pm UTC](https://discourse.julialang.org/t/locking-properties-of-abstractarrays/4141 "2017-06-07T15:27:37Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 7, 2017, 3:44pm UTC](https://discourse.julialang.org/t/locking-properties-of-abstractarrays/4141/2 "2017-06-07T15:44:30Z")

</div>

There are many different `AbstractArray` and they have different thread safety behavior.

In general though. `x_temp[i] +=` is **NEVER** thread safe if two thread access the same `i`. It can be thread safe if you can guarantee `i` are all different for different threads but not if different indices belongs to the same memory location which is the case for [`BitArray`](https://discourse.julialang.org/t/odd-behavior-from-threads-with-bitwise-and/3191/5)

Performance wise, you should make sure each thread work on different memory. What you are doing should be fine.

Note that I dont think LLVM has enough information to hoist the memory access to `x_temp` in `convolve!` it’ll be better if you do `xtempi = x_temp[i]` before the loop, `xtempi +=` in the loop and `x_temp[i] = xtempi` after the loop. This is not thread specific.

---

_[View the full topic](https://discourse.julialang.org/t/locking-properties-of-abstractarrays/4141)._
