thread_local vs boost :: thread_specific vs :: pthread_key_t

时间:2015-04-15 16:46:24

标签: c++

我有一个程序可以使一些库(所有C ++)运行,它们使用TLS作为变量(传递给所有库)。使用关键字' thread_local'并且使用' boost :: thread_specific',对于每个共享库,每个线程AND的变量存储都是不同的。使用' pthread_key_t'它只对每个线程都不同,它的行为与预期的一样。我想' boost :: thread_specific'使用' thread_local'这就是为什么它表现得像它。为什么' thread_local'表现得像这样?

$ clang --version
Ubuntu clang version 3.5.0-4ubuntu2~trusty2 (tags/RELEASE_350/final) (based on LLVM 3.5.0)
Target: x86_64-pc-linux-gnu
Thread model: posix

$ uname -a
Linux robert-y510p 3.13.0-49-generic #81-Ubuntu SMP Tue Mar 24 19:29:48 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

0 个答案:

没有答案