"Gang Ma"
Hi, I tried to use boost/thread library to write a program to read a large text file. The program compiled but did not get the right answer. I am not sure my usage of the library is correct. I appreciate your helps. Here are the code:#include <iostream>#include <fstream>#include <string>#include
#include #include #include //#include "stdafx.h"boost::mutex io_mutex;using namespace std;void mtread(char* filename,const int stidx, const int edidx,int id) { fstream infile; infile.open(filename); string line; if (infile.good()){ for (int linenum=stidx; linenum<=edidx;linenum++) { boost::mutex::scoped_lock lock(io_mutex); infile.seekg(linenum,ios::beg); getline(infile,line); cout<
This looks to me like an IO problem, not a thread problem. Replace your threads with direct calls to the functions, and I expect you'll see the same problem. seekg does not seek to a line, it seeks to a byte in the file. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL