开发者

Is there a threadsafe and generic IList<T> in c#?

开发者 https://www.devze.com 2023-01-07 18:07 出处:网络
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 safet

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.


System.Collections.Concurrent.BlockingCollection<T>

Link.


.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号