簡體   English   中英

使用pthreads將數據傳遞給線程(在C ++中)

[英]Passing data to threads using pthreads (in C++)

大家好,

這是這種情況,我有兩組線程,Mapper和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。

誰能闡明我該怎么做?

我希望我的描述足夠清楚,但是如果有幫助,我可以共享一些代碼。

有很多方法可以在線程之間共享數據。 您的示例表明您需要某種管道。 這意味着一個線程將數據推送到共享數據結構中,而目標線程將從同一結構中提取數據。 該數據結構可以是向量或受鎖保護的列表。 也可以使用無鎖機制(請參閱http://msdn.microsoft.com/zh-cn/library/windows/desktop/ms684121(v=vs.85).aspx )。 您可以在此處閱讀有關管道的更多信息: http : //msdn.microsoft.com/zh-cn/library/gg663538.aspx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM