Sun Studio 12: C User's Guide

B.2.146 -xthreadvar[=o]

Specify -xthreadvar to control the implementation of thread local variables. Use this option in conjunction with the __thread declaration specifier to take advantage of the compiler’s thread-local storage facility. After you declare the thread variables with the __thread specifier, specify -xthreadvar to enable the use of thread-local storage with position dependent code (non-PIC code) in dynamic (shared) libraries. For more information on how to use __thread, see 2.3 Thread Local Storage Specifier.

o must be one the following:

Table B–40 The -xthreadvar Flags

Flag  

Meaning  

[no%]dynamic

[[Do not] Compile variables for dynamic loading. Access to thread variables is significantly faster when -xthreadvar=no%dynamic but you cannot use the object file within a dynamic library. That is, you can only use the object file in an executable file.

If you do not specify -xthreadvar, the default used by the compiler depends upon whether or not position-independent code is enabled. If position-independent code is enabled, the option is set to -xthreadvar=dynamic. If position-independent code is disabled, the option is set to -xthreadvar=no%dynamic.

If you specify -xthreadvar, but do not specify any values, the option is set to -xthreadvar=dynamic.

If there is non-position-independent code within a dynamic library, you must specify -xthreadvar.

The linker cannot support the thread-variable equivalent of non-PIC code in dynamic libraries. Non-PIC thread variables are significantly faster, and hence should be the default for executables.

Using thread variables on different versions of Solaris software requires different options on the command line.

See Also: -xcode, -KPIC, -Kpic