Vultraz

Untitled

Apr 9th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1.     std::vector<std::thread> loader_threads;
  2.     loader_threads.reserve(surfs.size());
  3.  
  4.     std::mutex surf_lock;
  5.  
  6.     for(const auto& f : file_paths) {
  7.         loader_threads.emplace_back([&surf_lock, &surfs](const std::string path) {
  8.             surface temp = image::get_image(path);
  9.  
  10.             std::lock_guard<std::mutex> lock(surf_lock);
  11.  
  12.             if(!temp.null()) {
  13.                 surfs.push_back({ std::move(temp), path});
  14.             }
  15.         }, f);
  16.     }
  17.  
  18.     for(auto& thread : loader_threads) {
  19.         thread.join();
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment