gcc -ftls-model (-qtls)
Posted rtoax
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gcc -ftls-model (-qtls)相关的知识,希望对你有一定的参考价值。
https://www.ibm.com/docs/en/xl-c-and-cpp-linux/16.1.0?topic=descriptions-ftls-model-qtls
Category
Pragma equivalent
None.
Purpose
Enables recognition of the __thread storage class specifier, which designates variables that are to be allocated thread-local storage; and specifies the threadlocal storage model to be used.
When this option is in effect, any variables marked with the __thread storage class specifier are treated as local to each thread in a multithreaded application. At run time, a copy of the variable is created for each thread that accesses it, and destroyed when the thread terminates. Like other high-level constructs that you can use to parallelize your applications, thread-local storage prevents race conditions to global data, without the need for low-level synchronization of threads.
Suboptions allow you to specify thread-local storage models, which provide better performance but are more restrictive in their applicability.
Syntax
.-tls-model--+-=global-dynamic-+-.
| +-=local-dynamic--+ |
| +-=initial-exec---+ |
| '-=local-exec-----' |
>>- -f--+-no-tls-model-------------------+---------------------><
.-=default--------.
.-tls--+-=global-dynamic-+-.
| +-=initial-exec---+ |
| +-=local-exec-----+ |
| '-=local-dynamic--' |
>>- -q--+-notls--------------------+---------------------------><
Defaults
-qtls=default
Specifying -qtls with no suboption is equivalent to specifying -qtls=default.
The default setting for -ftls-model is the same as the default setting for -qtls.
Parameters
default (-qtls only)
Uses the appropriate model depending on the setting of the -fPIC (-qpic) option, which determines whether position-independent code is generated or not. When -fPIC (-qpic) is in effect, this suboption results in -qtls=global-dynamic. When -fno-pic (-fno-PIC, -qnopic) is in effect, this suboption results in -qtls=initial-exec .
global-dynamic
This model is the most general, and can be used for all thread-local variables.
initial-exec
This model provides better performance than the global-dynamic or local-dynamic models, and can be used for thread-local variables defined in dynamically-loaded modules, provided that those modules are loaded at the same time as the executable. That is, it can only be used when all thread-local variables are defined in modules that are not loaded through dlopen.
local-dynamic
This model provides better performance than the global-dynamic model, and can be used for thread-local variables defined in dynamically-loaded modules. However, it can only be used when all references to thread-local variables are contained in the same module in which the variables are defined.
local-exec
This model provides the best performance of all of the models, but can only be used when all thread-local variables are defined and referenced by the main executable.
Predefined macros
None.
Related information
Parent topic:
以上是关于gcc -ftls-model (-qtls)的主要内容,如果未能解决你的问题,请参考以下文章