Anonymous avatar Anonymous committed 0ebd6c1 Draft

[multithreading] +++

Comments (0)

Files changed (3)

WordSpellChecker.h

     std::ostream &m_outputStream;
 public:
     WordSpellChecker(std::istream &inputStream, std::ostream &outputStream);
-    void Run(bool isSingleThreaded = true);
+    void Run(bool isSingleThreaded = false);
 };

output/SynchronizedWordOutput.h

     bool TryOutputPending() {
         set<PendingWordOutput>::iterator it = m_pendingCorrections.begin();
         const PendingWordOutput &pending = *it;
-        if (pending.order == m_currentWordNumber) {
+        if (pending.order == m_currentWordNumber + 1) {
             OutputLastWordSpaceAndNextWord(pending.pWordCorrection);
+            m_pendingCorrections.erase(it);
             return true;
         } else {
             return false;
         }
-        m_pendingCorrections.erase(it);
-        return true;
+        return false;
     }
 
     void OutputLastWordSpaceAndNextWord(shared_ptr<WordCorrection> pWordCorrection) {
             }
             boost::this_thread::sleep(boost::posix_time::milliseconds(20));
         }
+        boost::lock_guard<boost::recursive_mutex> l(m_lock);
         FlushSpaces();
         m_pNextOutput->Flush();
     }

processor/MultithreadedProcessingStrategy.h

             if(GetNextWordToProcess(wordpair)) {
                 { // scope
                     boost::lock_guard<boost::recursive_mutex> l(m_lock);
+                    //std::cout << "processing " << wordpair.second << std::endl;
                     m_processing++;
                 }
+
+
                 shared_ptr<WordCorrection> pWordCorrections = m_pDictionary->GetCorrections(wordpair.second);
                 m_pWordOutput->OutputWord(wordpair.first, pWordCorrections);
 
                 { // scope
                     boost::lock_guard<boost::recursive_mutex> l(m_lock);
+                    //std::cout << "processed " << wordpair.second << std::endl;
                     m_processing--;
                 }
             } else {
+
                 boost::this_thread::sleep(boost::posix_time::milliseconds(15));
             }
         }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.