What is the performance penalty of C++11 thread_local variables in GCC 4.8?

后端 未结 3 1743
别跟我提以往
别跟我提以往 2020-12-07 10:58

From the GCC 4.8 draft changelog:

G++ now implements the C++11 thread_local keyword; this differs from the GNU __thread ke

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 11:18

    If the variable is defined in the current TU, the inliner will take care of the overhead. I expect that this will be true of most uses of thread_local.

    For extern variables, if the programmer can be sure that no use of the variable in a non-defining TU needs to trigger dynamic initialization (either because the variable is statically initialized, or a use of the variable in the defining TU will be executed before any uses in another TU), they can avoid this overhead with the -fno-extern-tls-init option.

提交回复
热议问题