Guest User

Untitled

a guest
Jun 17th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.15 KB | None | 0 0
  1. mutex m;
  2. volatile T *x;  // atomic<T*> in C++11
  3.  
  4. // ...
  5.  
  6. if (x == 0)
  7. {
  8.     lock_guard<mutex> _(m);
  9.     if (x == 0) x = new T();
  10. }
  11.  
  12. // read x
  13. // ...
Add Comment
Please, Sign In to add comment