TLS(Thread Local Storage)问题demo

#include #include #include #include using namespace std; thread_local unsigned int rage = 1; //unsigned int rage = 1; mutex cout_mutex; void increase_rage(const std::string& thread_name){ ++rage; // modifying outside a lock is okay; this is a thread-local variable lock_guard lock(cout_mutex); cout << "Rage counter for " << thread_name << " = " << rage << " ,line = " <<__LINE__<

    推荐阅读