Support thread local storage - Partially Fixes #291 #1019

Closed
alastairpatrick wants to merge 8 commits from thread-local-storage into develop
alastairpatrick commented 2022-09-10 17:19:09 -05:00 (Migrated from github.com)

This patch adds a pico_tls module, which adds support for GCC's __thread, C11's _Thread_local, and C++'s thread_local storage class specifiers. For example:

__thread int foo;

Different implementations of pico_tls may be selected by means of the pico_set_tls_implementation cmake macro, similar to some other SDK modules. For example, a different implementation could be selected if using an RTOS.

In this implementation, a thread corresponds to a core. No TLS storage is allocated for exceptions handlers. So there are two threads total.

Issue #291 has two parts: making C++ thread_local work and making C++ exceptions work. This patch adds support for thread_local but not C++ exceptions.

Tested by building SDK and running modified kitchen_sink in debug and release, stepping through tls_init and __wrap___emutls_get_address in GDB.

This patch adds a pico_tls module, which adds support for GCC's __thread, C11's _Thread_local, and C++'s thread_local storage class specifiers. For example: ```c __thread int foo; ``` Different implementations of pico_tls may be selected by means of the pico_set_tls_implementation cmake macro, similar to some other SDK modules. For example, a different implementation could be selected if using an RTOS. In this implementation, a thread corresponds to a core. No TLS storage is allocated for exceptions handlers. So there are two threads total. Issue #291 has two parts: making C++ thread_local work and making C++ exceptions work. This patch adds support for thread_local but not C++ exceptions. Tested by building SDK and running modified kitchen_sink in debug and release, stepping through tls_init and __wrap___emutls_get_address in GDB.
kilograham commented 2022-09-10 19:09:51 -05:00 (Migrated from github.com)

Nice; just glanced at this so far.

A couple o-things

  • We should probably not make core_thread the default (as it pulls in new extra code), by which i actually mean we should make it the default, but not unilaterally add pico_tls as a dependency. (i.e. add that if you want TLS)
  • Can you add our copyright (congratulations on perhaps being the first that i recall to add new code!) ... you can include your name as well if you want.
Nice; just glanced at this so far. A couple o-things * We should probably not make `core_thread` the default (as it pulls in new extra code), by which i actually mean we should make it the default, but not unilaterally add `pico_tls` as a dependency. (i.e. add that if you want TLS) * Can you add our copyright (congratulations on perhaps being the first that i recall to add new code!) ... you can include your name as well if you want.
alastairpatrick commented 2022-09-11 10:43:56 -05:00 (Migrated from github.com)

Copyright comments added to tls.c and tls.S but not CMakeLists.txt, which I think is consistent with other sources. I removed pico_tls from pico_runtime's dependencies, which I think is what you want.

Copyright comments added to tls.c and tls.S but not CMakeLists.txt, which I think is consistent with other sources. I removed pico_tls from pico_runtime's dependencies, which I think is what you want.
kilograham commented 2024-07-19 13:43:45 -05:00 (Migrated from github.com)

moving to 1.7.0 so we can fix this on clang too

moving to 1.7.0 so we can fix this on clang too
kilograham commented 2026-04-24 20:40:54 -05:00 (Migrated from github.com)

thank you; subsumed by https://github.com/raspberrypi/pico-sdk/pull/2910 (finally!!!)

thank you; subsumed by https://github.com/raspberrypi/pico-sdk/pull/2910 (finally!!!)

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk!1019
No description provided.