Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is List<T> constructor thread safe?

More specifically, is List(T)(IEnumerable(T)) thread-safe if the IEnumerable used to initialize the list is modified during the construction of the new list?

like image 763
scim Avatar asked Mar 18 '26 14:03

scim


1 Answers

That has nothing to do with the List constructor being thread safe, it only depends on whether the IEnumerable is thread safe.

The constructor is not thread safe, but that is not a problem in this case. The constructor is not doing anything that compromises it's thread safety, it's the thread safety of the IEnumerable that may be a problem.

like image 68
Guffa Avatar answered Mar 20 '26 03:03

Guffa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!