Support for C11/C++11 thread local storage

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
User avatar
stertingen
Posts: 21
Joined: Mon Jan 13, 2020 10:55 pm
Has thanked: 7 times
Been thanked: 7 times

Support for C11/C++11 thread local storage

Postby stertingen » Tue Jun 30, 2020 1:56 pm

C11 (https://en.cppreference.com/w/c/languag ... e_duration) and C++11 (https://en.cppreference.com/w/cpp/langu ... e_duration) introduce language keywords for thread local storage.

While it may be possible to define CH_CFG_THREAD_EXTRA_FIELDS to get some sort of thread local storage, it's not portable to POSIX or other OSes, so support for thread_local / _Thread_local would be nice.

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Support for C11/C++11 thread local storage

Postby Giovanni » Tue Jun 30, 2020 2:39 pm

Hi,

That is a compiler development, the OS already supports mechanisms able to implement that. For example a private heap that is destroyed on thread termination (using hooks).

Giovanni

User avatar
alex31
Posts: 379
Joined: Fri May 25, 2012 10:23 am
Location: toulouse, france
Has thanked: 38 times
Been thanked: 62 times
Contact:

Re: Support for C11/C++11 thread local storage

Postby alex31 » Wed Jul 01, 2020 11:01 am

the OS already supports mechanisms able to implement that. For example a private heap that is destroyed on thread termination (using hooks).


That's nice, can be useful for allocating memory from a dma compatible pool in a reentrant way. Is there any example of using this ?

Alexandre

User avatar
Giovanni
Site Admin
Posts: 14457
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: Support for C11/C++11 thread local storage

Postby Giovanni » Wed Jul 01, 2020 11:30 am

No examples so far, I am thinking to make the heap allocator "thread aware", each thread could allocate private blocks that are released on thread termination (or explicitly).

This would require an extra field in the header structure because each block would be linked to the thread using a list. It would also better support that C++ feature, no need to use hooks at all.

Giovanni


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 65 guests