Skip to content

examples/nxflat: Add tests of __thread and thread_local variables. - #3880

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:nxflat-tls
Oct 20, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:nxflat-tls

Conversation

@casaroli

Copy link
Copy Markdown
Contributor

Summary

Add two NXFLAT test modules. tls has a __thread variable without an initial value, one with an initial value, and a struct whose template holds a string pointer and a data pointer. tlsxx has a C++ thread_local object with a constructor and the static thread_local member of a class template. In each module, the main thread and a second thread check the initial values, change them, and check that the other thread does not see the change. tlsxx needs CONFIG_HAVE_CXX.

The module imports __emutls_get_address(), and the symbol table that mksymtab.sh generates from the thunks exports it, so the example needs no other change.

Impact

Two more modules in the ROMFS of examples/nxflat when pthreads are enabled (tlsxx also needs CONFIG_HAVE_CXX).

Testing

See apache/nuttx#20805. tlsxx needs that PR: with ldnxflat of master, exec() of tlsxx fails. The checks of the second thread need a base code that keeps a copy of each __thread variable per thread (#20723). eagle100:nxflat builds with the new module. tools/checkpatch.sh -c -u -m -g passes.

depends-on: [apache/nuttx/pull/20805 apache/nuttx/pull/20723]

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @casaroli :-)

Do we want to put these tests somehow into ostest as our basic and most popular testing routine? :-)

@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx-apps/actions/runs/39231789693

@casaroli casaroli closed this Oct 19, 2026
@casaroli casaroli reopened this Oct 19, 2026
tls has a __thread variable without an initial value, one with an
initial value, and a struct whose template holds a string pointer and a
data pointer.  The main thread and a second thread each check the
initial values and change them.  Each thread must not see the changes
of the other one.

tlsxx does the same with a C++ thread_local object with a constructor,
and with the static thread_local member of a class template.  Each
thread must construct its own objects at their first use.  The member
of the template is in COMDAT section groups.  tlsxx needs
CONFIG_HAVE_CXX.

With a toolchain that emulates TLS, a module imports
__emutls_get_address() from the base code, and the generated symbol
table exports it.  The checks of the second thread pass only if the
base code keeps a copy of each variable per thread.  The libgcc of such
a toolchain keeps one copy for all threads.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx-apps/actions/runs/39310472352

@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx-apps/actions/runs/39339269946

@xiaoxiang781216
xiaoxiang781216 merged commit 8ffa655 into apache:master Oct 20, 2026
56 of 82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants