AnsweredAssumed Answered

Thread Local Storage class MQX / ARM compiler?

Question asked by pmt on Jan 15, 2014



Is there some way to declare a variable to be placed in thread local storage in MQX?  Can someone point me to an example of this?  Caveat:  I am using MQX with the Arm (Keil) toolchain.  In this tool-chain there is a __declspec(thread) attribute in the compiler.  Example:


__declspec(thread) int i;

__thread int j;          // same as __declspec(thread) int j;


This targets the variable for a particular linker section.


I would suspect that you would have to declare a variable with this compile time attribute along with adding a special linker section that ultimately MQX understands to mean that this variable context is conditional on the currently running task.  It's not clear to me where or how to enable this, but I am sure another tool chain (Metaware) that I have used in the past with MQX implemented this feature.  So I know it should be possible.


Also, I'm not looking for a workaround solution.  I know I could allocate storage dynamically, or write a function that returns a value with sensitivity to the current task ID.  I would like to implement it with a compile time solution.