#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__<
【TLS(Thread Local Storage)问题demo】
推荐阅读
- Leetcode 练习 35.找到插入位置
- STL应用之输入任意个整数,并按从大到小排序并输入
- C语言缺陷与陷阱(3)
- C++学习|数组去重
- C++学习|Config Class
- C++ 宏定义 #define 和常量 const 的区别
- C++中Public Static和Private Static区别