Is it necessary to lock an array that is *only written to* from one thread and *only read from* another?

前端 未结 10 1487
后悔当初
后悔当初 2020-12-13 19:26

I have two threads running. They share an array. One of the threads adds new elements to the array (and removes them) and the other uses this array (read operations only).

10条回答
  •  庸人自扰
    2020-12-13 20:04

    It depends. One situation where it could be bad is if you are removing an item in one thread then reading the last item by its index in your read thread. That read thread would throw an OOB error.

提交回复
热议问题