2 #include <iostream> // std::cout
3 #include <thread> // std::thread
4 #include <mutex> // std::mutex
6 std::mutex mtx; // mutex for critical section
8 void print_block (int n, char c) {
9 // critical section (exclusive access to std::cout signaled by locking mtx):
11 for (int i=0; i<n; ++i) { std::cout << c; }
18 std::thread th1 (print_block,50,'*');
19 std::thread th2 (print_block,50,'$');