Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Online C++ Compiler.
- Code, Compile, Run and Debug C++ program online.
- Write your code in this editor and press "Run" button to compile and execute it.
- *******************************************************************************/
- #include <iostream>
- #include <thread>
- #include <mutex>
- std::mutex mutex_console;
- void f()
- {
- std::lock_guard<std::mutex> guard(mutex_console);
- std::cout << "print function f()" << std::endl;
- }
- int main()
- {
- std::string lol = "LOOOOL";
- std::string* lol_addr = &lol;
- std::thread t_f1(&f);
- std::thread t_f2(&f);
- {
- std::lock_guard<std::mutex> guard(mutex_console);
- std::cout << "lol = " << lol << std::endl;
- std::cout << "lol_addr = " << lol_addr << std::endl;
- std::cout << "lol_addr value = " << *lol_addr << std::endl;
- }
- t_f1.detach();
- t_f2.detach();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment