Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 872679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:49:14+00:00 2026-05-15T10:49:14+00:00

I searched google as much as I could but I couldn’t find any good

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:49:14+00:00Added an answer on May 15, 2026 at 10:49 am

    If the documentation says it is reentrant (and thus thread-safe), then it is.

    If ever there was a bug in the code (not your code) and the function wasn’t really thread-safe, there is nothing much you can do about it (unless using another function), and it’s not up to you to fix this in your code: the function must behave the way it is documented.

    However, I would be careful with the results given by valgrind. It is a great tool, and I use it often. But sometimes, it is just wrong. And for something as hard as detecting race conditions, I would be even more careful about what it says. Especially about a standard function that is beeing used for decades.

    My advice here would be: just ignore it. If you ever experience issues and believe localtime_r() is responsible for it, write to the appropriate mailing-list to report the issue, and/or use another function.

    In the meanwhile, you should be just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I searched on google about this but couldnt find much. I need to setup
I searched pretty much everywhere on google, but I didn't find anything useable. I
I've searched google and SO for a solution to this problem but have not
I have searched around Google and StackOverflow trying to find a solution to this,
I searched Google search APIs and didn't find a way to get a website
I searched in Google to find the differences between a case class and a
I have searched but apparently my google foo is weak. What I need is
I've googled around and searched the MYSQL docs ad nauseam and couldn't find a
I googled and searched for information regarding the title but most of them couldn't
I've searched Google for awhile now, doesn't seem like I am correctly searching it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.