In Java, is it required to synchronize write access to an array if each thread writes to a separate cell space?

前端 未结 10 1782
北恋
北恋 2020-12-15 17:14

Is it required to synchronize write access to an array in Java if each thread writes to a separate cell space?

EDIT: Specifically, the array is eith

10条回答
  •  难免孤独
    2020-12-15 17:44

    If read access is also partitioned in the same manner, then synchronization is not needed as per bkail's link.

    But if the threads read each other's writes, it would still be necessary to have a memory barrier to force synchronization of cache contents. Otherwise, threadys may get inconsistent read results.

提交回复
热议问题