Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <thread>
- #include <mutex>
- #include <unistd.h>
- std::mutex mtx;
- void print_block (int n, char c) {
- mtx.lock();
- for (int i = 0; i < n; i++)
- {
- std::cout << c;
- }
- std::cout << std::endl ;
- mtx.unlock();
- return;
- }
- int main()
- {
- std::thread th1(print_block, 50, '*');
- std::thread th2(print_block, 60, '$');
- th1.join();
- //my print statement
- std::cout << "In between thread joins" << std::endl;
- th2.join();
- return 0;
- }
Add Comment
Please, Sign In to add comment