Guest User

Untitled

a guest
Feb 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. #include <thread>
  2. #include <atomic>
  3. #include <vector>
  4. #include <unistd.h>
  5. using namespace std;
  6.  
  7. int main() {
  8. vector<thread> threads;
  9. atomic<bool> done { false };
  10. for (int i = 0; i < 20; i++) {
  11. threads.emplace_back([&]() {
  12. while (!done) { usleep(10000); }
  13. });
  14. threads.back().detach();
  15. }
  16. done = true;
  17. sleep(1);
  18. return 0;
  19. }
Add Comment
Please, Sign In to add comment