Is List thread-safe for reading?

后端 未结 4 1011
遥遥无期
遥遥无期 2020-12-17 08:08

Is the following pseudocode thread-safe ?

IList dataList = SomeNhibernateRepository.GetData();

Parallel.For(..i..)
{
    foreach(var item in dataLi         


        
4条回答
  •  执笔经年
    2020-12-17 08:21

    It's fully thread-safe as long as DoSomething(item) doesn't modify dataList. Since you said it doesn't, then yes, that is thread-safe.

提交回复
热议问题