Can a List be accessed by multiple threads?

后端 未结 4 2068

I am planning to share a List between multiple threads. The list will be locked during a changes, which happen infrequently. Is there a thread safety issue if multiple itera

4条回答
  •  时光取名叫无心
    2021-01-02 03:15

    List is not thread-safe generally. Having multiple readers will not cause any issues, however, you cannot write to the list while it is being read. So you would need to lock on both read and write or use something like a System.Threading.ReaderWriterLock (which allows multiple readers but only one writer).

提交回复
热议问题