Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <thread>
  2. #include <vector>
  3. #include <unordered_map>
  4.  
  5. class MyClass
  6. {
  7.     public:
  8.         MyClass(){
  9.             printf("%p\n", this);
  10.         }
  11.         ~MyClass(){
  12.             printf("~%p\n", this);
  13.         }
  14.  
  15.         std::unordered_map<int, int> member;
  16. };
  17.  
  18. thread_local MyClass threadLocalObject;
  19.  
  20. int main(){
  21.     std::vector<std::thread> threads;
  22.  
  23.     for (int i = 0; i < 40; ++i){
  24.         threads.emplace_back([](){
  25.             printf("%ld\n", threadLocalObject.member.size());
  26.         });
  27.     }
  28.  
  29.     for (auto &thread : threads)
  30.         thread.join();
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement