问题标签 [concurrent-queue]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
sorting - How to sort TBB concurrent_vector or concurrent_queue?
Now I have a solver in that I need to keep a set of self-defined data type objects in a concurrent_vector or queue. It has to be concurrent because the objects come from different threads.With this concurrent container, I hope to sort these objects, eliminate duplicates and send them back when other threads need them.
However, I know TBB offers concurrent_vector and concurrent_queue which can be read and written concurrently from different threads. But how to sort the objects inside a container? Does everyone know how to do that? Thanks.
c# - 在 ConcurrentQueue 中尝试出队
如果队列中没有项目,ConcurrentQueue 中的 TryDequeue 将返回 false。
如果队列为空,我需要我的队列将等到将新项目添加到队列中并将新项目出列,并且该过程将继续这样。
我应该在 C# 4.0 中使用 monitor.enter、wait、pulse 还是任何更好的选项
design-patterns - 可能产生更多工作的异步工作的设计模式是什么?
我一直在尝试优雅地处理异步工作线程既产生结果又(可能)识别更多需要完成的工作的情况。换个角度想,如果您正在遍历一棵树并在每个节点上工作,那么工作人员正在处理树中间的一个节点,并且发现了需要自己工作的子节点。
工作线程向作业队列添加更多作业是否合理设计?这将要求工作人员对它所属的并发系统有所了解,这对我来说似乎违反了一些不成文的规则。这个问题是如何解决的?
visual-studio-2010 - 将 Concurrency::concurrent_queue 与 std::unique_ptr 一起使用
我想使用 Visual Studio 2010 的并发库在线程之间传递操作。我有我的类SimpleAction
,指向它的指针存储在Concurrency::concurrent_queue
.
使用这个定义和“消费”逻辑它可以工作:
但是,当我将其更改为 std::unique_ptr 时,如下所示:
编译器给出以下错误消息:
似乎编译器不喜欢 concurrent_queue 中的这种构造:
这似乎合乎逻辑(我们不希望复制 std::unique_ptr (必须移动它)。
问题:
- 这是 Visual Studio 2010 的并发/PPL 库的已知问题/限制/功能吗?
- 这个问题在 Visual Studio 2012 中解决了吗?
- 还是我做错了什么?
谢谢,帕特里克
c++ - TBB concurrent_queue 使用示例
英特尔线程构建模块库包括一个concurrent_queue
容器。
concurrent_queue
不幸的是,在互联网上四处挖掘还没有产生TBB 库以并行方式使用的示例。
有人可以提供一个工作队列的示例,其中多个线程同时弹出项目并推送项目直到队列最终为空?
c# - concurrentQueue tryDequeue,结果未知
我正在尝试构建一种灵活的方法来处理不同类型的并发队列,因为大多数处理队列的逻辑是相同的。
它看起来有点像这样:
outResult 似乎是正确的类型,但我收到以下消息:“'System.Collections.Concurrent.ConcurrentQueue.TryDequeue(out WinformWith10pxNewProject1.TestData)' 的最佳重载方法匹配有一些无效参数”
事情是,当我这样做时它工作正常:
有什么办法可以解决类型的硬编码?将为我正在创建的方法提供很大的灵活性。
亲切的问候,
马蒂斯
c# - What is the best way to do a parallel Breadth First Search in C#?
As the title says, I'm looking for the best way to do a parallel BFS in C#. I want it to be as fast as possible and use as little memory as possible. If there is no 'best' way, what are good options?
I want to use this for solving a puzzle (in my case Rush Hour). My current algorithms use a taboo HashSet
which contains all previously explored states. This prevents high memory usage and significantly increases the speed of the algorithm. I currectly have a sequential and a parallel version of my algorithm. The sequential version is always faster or equally fast. This is my current parallel code:
Now there are problems with this I can see myself.
- ConcurrentQueue is not wait-free. I assume it has built-in locks which makes it use extra time.
- If the solution is found, other iterations of the
Parallel.ForEach
will continue running. I have tried solving this with cancellation tokens and parallel states, but it doesn't seem to work (or at least it doesn't improve the running time). - States can be explored multiple times, since a state can be found in multiple iterations of the foreach loop before it is added to the taboo list.
- I'm not sure if
Parallel.ForEach
is the best way to solve my problem.
I have searched around the internet, including stackoverflow, but I can't find any algorithm that solves the problem. Everyone seems to use Parallel.ForEach
and ConcurrentQueue
. But I'm sure there are better options.
Any help is appreciated!
c# - 我可以并行添加到 ConcurrentQueue 并从中产生吗?
我有一个从 Web 服务获取对象的类。我对这些对象的使用不依赖于顺序,因此我并行发出我的 Web 请求并将结果添加到ConcurrentQueue
.
同时,随着请求的产生,我们可以处理响应。
因此,我希望能够在将ConcurrentQueue
我的项目添加到其中时迭代其内容。
我怎样才能让一个班级填满队列而另一个班级清空它。它几乎肯定会比填充物更快地被清空,所以我不能在没有 a 的情况下枚举它,yield
因为集合将是空的并且不会等待。
c# - BackgroundWorker 和 ConcurrentQueue
我有一个FileSystemWatcher
正在寻找新文件,将文件名放在Queue
. 在一个单独的线程中,队列被关闭。我的代码正在运行,但我怀疑是否会因为异步过程而丢失信息。请观看评论解释的代码:(我想也许我需要某个地方的线程锁之类的东西?)(代码已简化)
c# - 在 c# 中使用阻塞集合进行数据库访问和下载图像
我正在开发一个表单上有两个按钮的程序。第一个执行访问数据库的功能,而其他从数据库下载图像并将其与 3 个图像副本(缩略图、缩放、小)一起保存。
访问数据库的代码
访问数据库后,下一个任务是下载图像,生成它的三个副本并将所有内容保存在一个文件夹中。为此,我正在尝试使用BlockingConnection<>
. 生产者部分执行下载原始图像并保存的功能,而消费者部分执行访问生产者队列以获取图像然后生成副本的功能。
实现 BlockingCollection 的代码
让我告诉你,当我用 BackgroundWorker 测试这段代码时,它运行得非常好。我收到错误的部分是尝试将图像保存在 Task1 中的行。
它抛出了这个异常
我想通了为什么它不保存图像。我已经相应地更改了代码。但它没有正确循环。在获得一个图像并生成其多个副本后,它应该返回第一个 foreach,下载新图像并生成其副本。