daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Feb 13th, 2018 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <thread>
  3. #include <mutex>
  4. #include <unistd.h>
  5.  
  6. std::mutex mtx;
  7.  
  8. void print_block (int n, char c) {
  9.     mtx.lock();
  10.     for (int i = 0; i < n; i++)
  11.     {
  12.         std::cout << c;
  13.     }
  14.     std::cout << std::endl ;
  15.     mtx.unlock();
  16.  
  17.     return;
  18. }
  19.  
  20. int main()
  21. {
  22.     std::thread th1(print_block, 50, '*');
  23.     std::thread th2(print_block, 60, '$');
  24.  
  25.     th1.join();
  26.     //my print statement
  27.     std::cout << "In between thread joins" << std::endl;
  28.     th2.join();
  29.  
  30.     return 0;
  31. }
RAW Paste Data
Top