Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<thread>
- #include<mutex>
- using namespace std;
- mutex semaforo;
- void imprime(int n, char c)
- {
- semaforo.lock();
- for(int i = 0; i < n; i++)
- {
- cout << c ;
- }cout << endl;
- semaforo.unlock();
- }
- int main()
- {
- thread t1(imprime, 50, 'a');
- thread t2(imprime, 50, 'b');
- thread t3(imprime, 50, 'c');
- thread t4(imprime, 50, 'd');
- t1.join();
- t2.join();
- t3.join();
- t4.join();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement