Thread local storage (TLS) is a mechanism that allows each thread to have its own
copy of a variable. This is useful for variables that are used by multiple
functions in a thread, but should not be shared with other threads.
There are some approaches to using TLS in NuttX:
1. Use the ``pthread_key_create()`` and ``pthread_setspecific()`` that from the POSIX standard. This is the most portable approach, but it requires that
the platform support pthreads.
2. Use the ``thread_local`` or ``__thread`` keyword from the C standard: https://gcc.gnu.org/onlinedocs/gcc/extensions-to-the-c-language-family/thread-local-storage.html
Configuration
=============
..code-block:: console
CONFIG_SCHED_THREAD_LOCAL /* Enable native thread local storage support */
Enable it to support native thread local storage, which is required that the compiler configured with ``--enable-tls`` option, this approach is more efficient if the compiler support it.
If your compiler support it then you still need further configuration to use it:
1. Enable ``CONFIG_SCHED_THREAD_LOCAL`` in menuconfig
2. Handle ``tbss`` and ``tdata`` sections in linker script, your can refer to the example in rv-virt
To confirm that your compiler supports TLS, you can try this command: