[En-Nut-Discussion] Thread-safe version of asctime
Harald Kipp
harald.kipp at egnite.de
Wed May 7 12:50:00 CEST 2014
Hi,
the recently added asctime.c contains a few comments
/*
Note: This function is *not* thread safe, because it uses a static
variable
to store the calculated values. To be safe, you must surround the call
to asctime
_and_ the usage of the returned pointer with NutEnterCritical() and
NutExitCritical()!
Provided for compatibility to std c lib.
*/
which I think are misleading. I cannot see, at which place we have to
expect a context switch.
The problem with static buffers is still there, e.g.
printf("%s %s", asctime(t1), asctime(t2));
will print out t2 twice and discard t1. IMHO, NutEnterCritical()
wouldn't solve this.
Furthermore I'm not sure about
static const char wday_name[][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
AFAIK, sizeof("Sun") is 4, not 3.
Regards,
Harald
More information about the En-Nut-Discussion
mailing list