I am using localtime in a multi-threaded application.
I have to replace it with a thread-safe version, which to my understanding is called localtime_r.
However, when I do so, I am unable to complete the build, due to a linkage failure.
I am not even sure where to start looking for the solution.
My system components are:
- Chip - STM32 (ARM based cortex)
- IDE - IAR (compiler and linker for ST-Microcontrollers)
- OS - ThreadX
I'm assuming (though I'm not sure about it), that this function would typically be supplied within the standard libraries provided along with the IDE. Am I correct?
Is there another library that I need to add to my project, or is it something in the project settings?
If there is no viable way to "import" this function into my code, what other options do I have for a thread-safe version of the localtime function?
UPDATE:
I am looking to avoid the use of OS resources (i.e., a mutex), and instead call a standard routine which does exactly what 'localtime' does, only without the static structure that it uses (making it thread-unsafe).
I don't see any reason why localtime would use a static structure to begin with, so I assume that the corresponding localtime_r does not solve it with any OS resources whatsoever, but merely refrains the use of a static structure.
If no such option is viable, then I might as well implement it myself, only I prefer to use something that has already been tested properly, due to the "irregularity" of the dating system.
The question here is, how do I link localtime_r' into my project (NOT how to implement localtime_r).
Thanks