为什么没有 ConcurrentList

发布于 2024-12-11 15:06:41 字数 274 浏览 7 评论 0原文

新的命名空间 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一直在等你来 2024-12-18 15:06:41

如果两个线程同时添加项目,您会对“订单”有什么期望?如果您想要的是 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.

ˇ宁静的妩媚 2024-12-18 15:06:41

随机访问对于从另一个线程更改的数据结构没有多大意义。

如果您查看并发集合,您会注意到它们的接口是专门设计用于与多线程访问良好配合的。我想不出一个可以与多线程代码很好地配合的有用的类似列表的界面。

如果元素从不移动,那么随机多线程访问是有意义的,但你有一个数组。

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.

Bonjour°[大白 2024-12-18 15:06:41

早在 2011 年 我写了一个 < code>ConcurrentListclass(代码可在 GitHub 上获取),其中是线程安全的、无锁的,并且实现了IList接口的一些

值得注意的是,不支持除 Add 之外的任何改变列表的操作;即,它是一个仅附加集合。所以 InsertRemoveAt 等不起作用。

Back in 2011 I wrote a ConcurrentList<T> class (code available on GitHub), which is thread-safe, lock-free, and implements some of the IList<T> interface.

Notably, any operations that mutate the list other than Add are not supported; i.e., it is an append-only collection. So Insert, RemoveAt, etc. don't work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文