0
這裏的情況,我有兩套線程,映射器和減壓器
映射器解析文本文件和發送帶有有行號個別單詞基於哈希函數
減速齒輪減速線程有一個固定的緩衝區大小,並在緩衝區中的每個字的地方,一個列表
我有映射器和減速線成單獨的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
任何人都可以擺脫我如何能做到這一點一些輕?
我希望我的描述足夠清楚,但是如果有幫助,我可以分享一些代碼。
你看到了嗎? http://stackoverflow.com/questions/11352249/memory-sharing-between-c-threads – Lrrr 2014-10-29 06:15:00
你可以使用條件變量來設計解決方案 – Nik 2014-10-29 06:15:55
它幾乎是消費者製造商的問題。你可以使用線程安全隊列解決它 – qwr 2014-10-29 06:21:49