Thanks, guys. I change my code a bit. The results are right. But I suspect it never used thread, but excute the thread one by one.

new code

void mtread(char* filename,const int stidx, const int edidx,int id) {

    fstream infile;
    infile.open(filename);
    string line;
    int linenum = 0;

    if (infile.good()){

        while (! infile.eof()) {
        boost::mutex::scoped_lock lock(io_mutex);

    //    infile.seekg(linenum,ios::beg);
        getline(infile,line);
 
        if (linenum>=stidx &&  linenum<=edidx){
            cout<<id << " : " <<line<<endl;
            //cout<<linenum<<endl;
            linenum++;
        }
        else
        {
            linenum++;
            if (linenum>edidx)
                break;
        }
    }

}
 else
 {    cerr<< "file " << filename << " cannot be opened for reading" <<endl;
 }

infile.close();
}


I got the same results running the program twice.


1 : 1
1 : 2
1 : 3
1 : 4
1 : 5
2 : 6
2 : 7
2 : 8
2 : 9
2 : 10

Thank for your helps.


regards,

gma