"is the list<t>.addrange() thread safe?" Code Answer


no, its documentation does not say it is thread safe, therefore it is not.

public static (shared in visual basic) members of this type are thread safe. any instance members are not guaranteed to be thread safe.

as to what can go wrong, think about what addrange(newitems) does:

  • check if there is enough space in the internal array
  • if not:
    • allocate a new array
    • copy the current items to the new array
    • set a field to point at the new array
  • copy the newitems to the correct local in the internal array
  • update the “count” field (this is used to control where the next item is inserted)

now think what will happen if the above is mixed up with another call to addrange() or even just a call to read an item.

By pb. on May 2 2022

Answers related to “is the list<t>.addrange() thread safe?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.