Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <thread>
- #include <vector>
- #include <iostream>
- #include <mutex>
- std::mutex mutex;
- void hello(int x) {
- mutex.lock();
- std::cout << "Hello, Concurrent World!" << x << '\n';
- mutex.unlock();
- return;
- }
- int main() {
- int x;
- std::vector<std::thread> arr;
- std::cin >> x;
- for (int i = 0; i < x; i++) {
- arr.push_back(std::thread(hello, i));
- }
- for (int i = 0; i < x; i++) {
- arr[i].join();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment