Changeset 4972 for icGREP


Ignore:
Timestamp:
Mar 14, 2016, 10:48:00 AM (4 years ago)
Author:
lindanl
Message:

multithreading with arbitrary number of threads and input files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4968 r4972  
    1616#include <boost/uuid/sha1.hpp>
    1717#include <toolchain.h>
    18 #include <atomic>
     18#include <mutex>
    1919
    2020static cl::OptionCategory aRegexSourceOptions("Regular Expression Options",
     
    104104
    105105GrepEngine grepEngine;
    106 std::atomic<int> fileCount;
     106std::mutex count_mutex;
    107107
     108size_t fileCount;
    108109void *DoGrep(void *threadid)
    109110{
    110111    long tid;
    111112    tid = (long)threadid;
    112     if (tid+1 < inputFiles.size())
    113         grepEngine.doGrep(inputFiles[tid+1]);
     113    size_t fileIdx;
     114
     115    count_mutex.lock();
     116    fileCount++;
     117    fileIdx = fileCount;
     118    count_mutex.unlock();
     119   
     120    while (fileIdx < inputFiles.size()){
     121        grepEngine.doGrep(inputFiles[fileIdx]);
     122       
     123        count_mutex.lock();
     124        fileCount++;
     125        fileIdx = fileCount;
     126        count_mutex.unlock();
     127    }
    114128
    115129    pthread_exit(NULL);
Note: See TracChangeset for help on using the changeset viewer.