为什么没有 ConcurrentList
新的命名空间 System.Collections.Concurrent 包含字典、队列和堆栈以及其他类的并发集合。有人知道为什么没有 ConcurrentList 吗?
更新
我发布了一个新问题来解释我当前的情况。我更喜欢改变原始问题的整体含义。这是新问题的链接。
The new namespace System.Collections.Concurrent contains concurrent collections for dictionary, queue and stack among other classes. Anyone know why is it that there is no ConcurrentList?
UPDATE
I've posted a new question explaining my current scenario. I preferred that to changing the whole sense of the original question. Here's the link to the new question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果两个线程同时添加项目,您会对“订单”有什么期望?如果您想要的是 ConcurrentBag 更合适物品的集合。
If two threads added items simultaneously what expectation of 'order' would you have? ConcurrentBag is more appropriate if all you want is a collection of items.
随机访问对于从另一个线程更改的数据结构没有多大意义。
如果您查看并发集合,您会注意到它们的接口是专门设计用于与多线程访问良好配合的。我想不出一个可以与多线程代码很好地配合的有用的类似列表的界面。
如果元素从不移动,那么随机多线程访问是有意义的,但你有一个数组。
Random access doesn't make much sense on a data structure that's changed from another thread.
If you look at the concurrent collections, you'll notice that their interface is specifically designed to work well with multi threaded access. I can't think of a useful list-like interface that works well with multithreaded code.
Random multi threaded access can make sense if the elements are never moved, but then you have an array.
早在 2011 年 我写了一个 < code>ConcurrentListclass (代码可在 GitHub 上获取),其中是线程安全的、无锁的,并且实现了
IList
接口的一些。值得注意的是,不支持除
Add
之外的任何改变列表的操作;即,它是一个仅附加集合。所以Insert
、RemoveAt
等不起作用。Back in 2011 I wrote a
ConcurrentList<T>
class (code available on GitHub), which is thread-safe, lock-free, and implements some of theIList<T>
interface.Notably, any operations that mutate the list other than
Add
are not supported; i.e., it is an append-only collection. SoInsert
,RemoveAt
, etc. don't work.