簡體   English   中英

當兩個線程讀取文件並標記化CSV文件時,c ++ Boost Multithread運行緩慢

[英]c++ Boost Multithread Running Slow when two threads read file and tokenize the CSV File

我有兩個功能,它曾經為我工作,我對代碼做了一些更改,但我不知道發生了什么。 當我將這些功能作為多線程執行時,CPU占用了10%到30%的速度,而且速度非常慢。 它只是逐行讀取文件,然后使用boost令牌解析CSV行。

        boost::thread OffLineUL(&AvaTTi::AvaCollectTTiAdvance::UeAndCellParamParseUL,c,tracefilenameUL.c_str(),NumOfLines,GHOSTFILTER,"","/",OffLineMode,OPENEXCELAUTO);
        boost::thread OffLineDL(&AvaTTi::AvaCollectTTiAdvance::UeAndCellParamParseDL,c,tracefilenameDL.c_str(), NumOfLines,"","/",OffLineMode,OPENEXCELAUTO);
        OffLineDL.join();
        OffLineUL.join();


    int AvaCollectTTiAdvance::UeAndCellParamParseDL(const char *inname, int NumOfRecords, const char *UserDir, const char* CurrentDir, int OffLineMode, int OPENEXCELAUTO)
    {
       typedef boost::tokenizer <boost::escaped_list_separator<char> > my_tokenizer;
       vector <string> mystr;


      std::ifstream infile(TTiAsciiTraceOutputUserDir.str(),std::ios::in);
      while (getline(infile, line)  && lineCount <= NumOfRecords)

      for (my_tokenizer::iterator it(tok.begin()), end(tok.end()); it != end; ++it)
      { 
        mystr.push_back(*it);
      }
      ....................
      ....................

誰能幫忙嗎? 我的想法耗盡了。 謝謝。

如果您在線程之間共享了資源,例如向量mystr,則需要使用線程同步機制來訪問這些資源,否則向量將被破壞。

如果將至少由一個線程寫入多個線程,則將立即從多個線程訪問的任何變量都是如此。

我不能說問題出在哪里,因為您沒有提供足夠的數據,我無法從您的代碼中看出哪些變量是局部變量,哪些不是局部變量,哪些變量僅由一個或多個線程使用。

暫無
暫無

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

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