SHARE
TWEET

Untitled

a guest Sep 19th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. std::recursive_mutex g_myDataMutex;
  2. std::string myString ;
  3.  
  4. void SetValueSync(std::string const in_newValue)
  5. {
  6.     for (int i = 0; i<10000; i++)
  7.     {
  8.         std::lock_guard<std::recursive_mutex> myLock(g_myDataMutex);
  9.         myString = myString + in_newValue;
  10.     }
  11. }
  12.  
  13. int main()
  14. {
  15.     std::thread t1(SetValueSync, "ABC");
  16.     std::thread t2(SetValueSync, "___");
  17.     t2.join();
  18.     t1.join();
  19.  
  20.     cout<<myString;
  21.     return 0
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top