Advertisement
Maco153

Attempt2.cpp

Mar 21st, 2020
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include "StudentFile.h"
  2. #include <chrono>
  3. #include <future>
  4. using namespace std;
  5. using namespace std::chrono;
  6.  
  7. int main(int argc, char** argv){
  8.  
  9. if (argc!=2)
  10. {
  11. cerr<<"Too much or too less arguments\n";
  12. exit(1);
  13. }
  14.  
  15. StudentList* mylist;
  16. mylist=new StudentList;
  17.  
  18.  
  19. std::mutex* shared;
  20. //StudentFile mine(mylist,argv[1]);
  21. StudentFile* mine=new StudentFile(mylist,argv[1]);
  22.  
  23. mine->set_mutex(shared);
  24. cout<<"hello from before the first thread \n";
  25. std::thread t1(&StudentFile::processFile,mine,mine);
  26.  
  27. std::thread t2(&StudentFile::processFile,mine,mine);
  28. std::thread t3(&StudentFile::processFile,mine,mine);
  29. cout<<"hello from after the first thread \n";
  30. t1.join();
  31. t2.join();
  32. t3.join();
  33.  
  34.     cout<<"hello form after the mutex \n";
  35. /*
  36. std::future<int> a = std::async(std::launch::async, &StudentFile::processFile,mine, mine);
  37. std::future<int> b = std::async(std::launch::async, &StudentFile::processFile,mine, mine);
  38.     cout<<"hello from the async mutex \n";
  39.  
  40.     std::chrono::milliseconds span (100);
  41.  
  42. while (a.wait_for(std::chrono::milliseconds(10000)) != future_status::ready) cout << "a:" << a.get() << endl;;
  43. while (b.wait_for(std::chrono::milliseconds(10000)) != future_status::ready)cout << "b:" << b.get() << endl;  ;
  44. */
  45.  
  46.  
  47.  
  48.  
  49.  
  50. cout<<"hello world\n";
  51.  
  52. delete mine;
  53. delete mylist;
  54. return 0;
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement