Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since your file size are relatively smaller and as you have to deal with number of files, the a better design would be to create two threads,</p> <p> <pre> 1. First thread reading and processing only files placed at even number in the file listing (ls -l in *nix). 2. Second thread reading the oddly placed file in the listing. </pre> </p> <p>The disadvantage of the method you mentioned of "one thread reading data into a vector and another thread reading from it" would be that you will have to be concerned of thread races and needs to prevent it by using mutex's and condition varibles.</p> <p> Where as this method would not require any locking [Hope there is no dependency between the data between files] </p> <p>Also, the faster way to read data from a file would be to binary read a file into a buffer of suitable size.</p> <p> Hope the answer helps you. </p> <p> **EDIT:** <p> As per your comment, it seems that you will have to go with one thread reading data into a queue data structure [a queue of char buffer maybe] and the second thread reading data from queue and processing it. </p> <p> As mentioned earlier the problem would be to read and write from the same queue as STL containers are not thread safe. </p> <p> So what I can recommend here is that manage your shared data structure i.e queue here using locaks and all else go for : <pre> 1. Boost Lock free : <a href="http://tim.klingt.org/boost_lockfree/lockfree/introduction.html" rel="nofollow"> Boost lock free </a> 2. Write your own loack free implementation : <a href="http://drdobbs.com/architecture-and-design/210604448" rel="nofollow"> Lock free impl </a> </pre> </p> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload