localtime_r supposed to be thread safe, but causing errors in Valgrind DRD

Posted by Nik on Stack Overflow See other posts from Stack Overflow or by Nik
Published on 2010-06-17T08:15:23Z Indexed on 2010/06/17 9:13 UTC
Read the original article Hit count: 271

Filed under:
|
|
|

I searched google as much as I could but I couldn't find any good answers to this.

localtime_r is supposed to be a thread-safe function for getting the system time. However, when checking my application with Valgrind --tool=drd, it consistantly tells me that there is a data race condition on this function. Are the common search results lying to me, or am I just missing something? It doesn't seem efficient to surround each localtime_r call with a mutex, especially if it is supposed to by thread safe in the first place. here is how i'm using it:

timeval handlerTime;
gettimeofday(&handlerTime,NULL);

tm handlerTm;
localtime_r(&handlerTime.tv_sec,&handlerTm);

Any ideas?

© Stack Overflow or respective owner

Related posts about c++

Related posts about thread