Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1.  
  2. void boarding(Runway &runway, Que &passQue, int i) {
  3. while(condition) {
  4. if(runway.getLength() > 0 && runway.getFreePlaces() > 0) {
  5. std::unique_lock<std::mutex> que_lock(m_data);
  6. cv_data.wait(que_lock, []{return ready;});
  7.  
  8. cv_passQue.notify_all();
  9. runway.addPassenger(passQue.popPassenger());
  10. processed = true;
  11. }
  12. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  13. }
  14.  
  15. }
  16.  
  17. void getPassenger(Que &passque) {
  18. while(condition) {
  19. // ready = false;
  20. if(passque.getPassengersLength() > 0){
  21. processed = false;
  22. std::lock_guard<std::mutex> lk(m_data);
  23. ready = true;
  24. cv_data.notify_one();
  25.  
  26. std::unique_lock<std::mutex> l(m_data);
  27. cv_data.wait(l, []{return processed;});
  28. }
  29. std::this_thread::sleep_for(std::chrono::milliseconds(100));
  30. }
  31.  
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement