Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "StudentFile.h"
- StudentFile:: StudentFile(){
- mtx=NULL;
- }
- StudentFile::StudentFile(StudentList * p_studentList,const char * filename){
- cout<<"From the constructor\n";
- student_file.open(filename,ios::in);
- studentList = p_studentList;
- }
- void StudentFile:: set_mutex(std::mutex* my){
- cout<<"hello form the mutex \n";
- mtx=my;
- cout<<"hello form the mutex \n";
- }
- int StudentFile::processFile(StudentFile* name){
- cout<<"from the processFile begin\n";
- //std::lock_guard <std::mutex> lock (name-> *mtx);
- int processed_students = 0;
- if ( !student_file.is_open()) return processed_students;
- string line="";
- string id = "";
- string fname="";
- string mname="";
- string lname="";
- string gpa="";
- cout<<"from before the locking\n";
- name->mtx->lock();
- while(getline(student_file,line)) {
- stringstream iss(line);
- getline(iss, id, ',');
- getline(iss, fname, ',');
- getline(iss, mname, ',');
- getline(iss, lname, ',');
- getline(iss, gpa, ',');
- *studentList += new Student(atol(id.c_str()),
- fname.c_str(),
- mname.c_str(),
- lname.c_str(),
- atof(gpa.c_str()));
- processed_students++;
- }
- name->mtx->unlock();
- cout<<"From after the unlocking\n";
- return processed_students;
- }
- int StudentFile::startThread(StudentFile * me) { return me->processFile(me); }
- StudentFile::~StudentFile() {
- if ( student_file.is_open()) {
- student_file.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement