Is List<T> or HashSet<T> or anything else built in threadsafe for addition only?
My question is similar to Threadsafe and generic arraylist? but I’m only looking for safety to cover adding to this list threaded, not removal or reading from it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
.NET 4.0 you could use the
BlockingCollection<T>, but that is still designed to be thread safe for all operations, not just addition.In general, it’s uncommon to design a data structure that guarantees certain operations to be safe for concurrency and other to not be so. If you’re concerned that there is an overhead when accessing a collection for reading, you should do some benchmarking before you go out of your way to look for specialized collections to deal with that.