Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <thread>
- #include <vector>
- #include <unordered_map>
- class MyClass
- {
- public:
- MyClass(){
- printf("%p\n", this);
- }
- ~MyClass(){
- printf("~%p\n", this);
- }
- std::unordered_map<int, int> member;
- };
- thread_local MyClass threadLocalObject;
- int main(){
- std::vector<std::thread> threads;
- for (int i = 0; i < 40; ++i){
- threads.emplace_back([](){
- printf("%ld\n", threadLocalObject.member.size());
- });
- }
- for (auto &thread : threads)
- thread.join();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement