c++11 thread_local

来源:互联网 发布:7.0数据库 编辑:程序博客网 时间:2024/06/10 20:30

thread_local 线程独有的变量


可用场景:

1.打印请求id,以此辨别从源头的业务业务代码一直能被跟踪


可能遇到的问题:

1.全局变量问题

解决方案:

.h

extern thread_local std::string r_id;


.cpp

thread_local std::string r_id;

0 0
原创粉丝点击