Bug in wiced_time (WICED/internal/time.c)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

All the functions in WICED/internal/time.c doesn't handle the case when the timer is overflown. Be careful. I'd suggest writing your own time functions.

6 Replies
GauravS_31
Moderator
Moderator
Moderator
10 questions asked 250 solutions authored 250 sign-ins

Your statement is not clear. Can you please explain with detail how the timer is overflown?

0 Likes
GauravS_31
Moderator
Moderator
Moderator
10 questions asked 250 solutions authored 250 sign-ins

We do not see any problem of timer overflow in time.c. You can use wiced_time_set_utc_time_ms() to set UTC time in milliseconds, which uses data type of uint64_t. You can use wiced_time_get_iso8601_time() to get the UTC time in iso 8601 format.

The bug is real, unfortunately you don't see the problem.

Try create 2 threads and make them just print the timestamp in a endless loop.

Make the device run several hours (or days) then you will be surprised by the timestamp output.

0 Likes

@Axel

Would be really helpful for me when you upload a complete project here. Is the problem related to "two threads"? Anything not quite Thread-safe???

Bob

0 Likes

The functions wiced_time_get_* are not thread safe.  You'll need to synchronize it or just avoid using it across threads...  The root of the problem is that the function wiced_time_get_utc_time_ms is not immutable.  If two threads call that function at the same time the results can be very unpredictable.

-Rob

0 Likes

The problem with the overflow is simple - review the source. The UTC time is set by adding a delta based on the tick timer difference from the last time the UTC get time was called. If the tick timer overflows (47.2 Days) then the results will be wrong.

Regarding non-thread safe, we see the same issue and will be making a patch.