[development][C][thread_local] 线程全局变量

 

线程全局变量, 线程本地存储, thread_local storage

只需要在变量定义的最前边添加 __thread 关键字.

 

用法:

https://gcc.gnu.org/onlinedocs/gcc-3.4.1/gcc/Thread-Local.html

 

原理:

http://docs.oracle.com/cd/E19253-01/819-7050/chapter8-1/index.html

 

性能分析:

https://software.intel.com/en-us/blogs/2011/05/02/the-hidden-performance-cost-of-accessing-thread-local-variables

基本上可以理解为每次方法变量,都多调用了一个函数 __tls_get_addr

 

 

中文介绍:

http://blog.csdn.net/wuhui_gdnt/article/details/6301887

 

方法二:

  使用POSIX线程接口中的KEY.

 

posted on 2017-10-17 16:34  toong  阅读(429)  评论(0编辑  收藏  举报