IamLupo

Untitled

Jan 29th, 2026
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C++ Compiler.
  4. Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <thread>
  11. #include <mutex>
  12.  
  13. std::mutex mutex_console;
  14.  
  15. void f()
  16. {
  17. std::lock_guard<std::mutex> guard(mutex_console);
  18.  
  19. std::cout << "print function f()" << std::endl;
  20. }
  21.  
  22. int main()
  23. {
  24. std::string lol = "LOOOOL";
  25. std::string* lol_addr = &lol;
  26.  
  27. std::thread t_f1(&f);
  28. std::thread t_f2(&f);
  29.  
  30. {
  31. std::lock_guard<std::mutex> guard(mutex_console);
  32.  
  33. std::cout << "lol = " << lol << std::endl;
  34. std::cout << "lol_addr = " << lol_addr << std::endl;
  35. std::cout << "lol_addr value = " << *lol_addr << std::endl;
  36. }
  37.  
  38. t_f1.detach();
  39. t_f2.detach();
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment