【发布时间】:2014-12-24 18:13:34
【问题描述】:
大家好,
情况是这样,我有两组线程,Mappers和Reducers
Mappers 解析文本文件并基于散列函数将带有行号的单个单词发送到减速器线程
Reducers 具有固定的缓冲区大小,并将该缓冲区中的每个单词放在一个列表中
我将 Mappers 和 Reducer 线程放入单独的 Pthread 数组中
For example:
[Step 1] For the word "example" Mapper thread produces a hash value of 3
[Step 2] Mapper thread puts "example" and its line number in the 4th
reducer's threads (0,1,2,3) buffer
[Step 3] Reducer thread #4 will place "example" with its
line number to the list
如果不清楚,请告诉我。
问题
我不知道如何将信息从映射器线程传递到适当的用户线程,所以第 2 步。
谁能告诉我如何做到这一点?
我希望我的描述足够清楚,但是如果有帮助,我可以分享一些代码。
【问题讨论】:
-
您可以使用条件变量来设计解决方案
-
这几乎是消费者生产者的问题。你可以使用线程安全队列解决它
-
现有的 MapReduce 算法有什么问题?例如,QtConcurrent 是一个易于使用的库,除了 Threading 之外还包含 MapReduce 算法。
标签: c++ multithreading pthreads