Re: linux time functions thread safety

I know that some of the time functions on linux are not thread safe, e.g. gmtime, ctime, since they return a pointer to a static allocated struct.

Does anyone knows if the two following time functions are thread safe ?
1)  time_t time ( time_t * timer );
2)  int gettimeofday(struct timeval *tv, struct timezone *tz);

Are there any issues I should be aware to when using these functions (I'm working with C++ on linux) ?

Thanks in advance.

Re: linux time functions thread safety

Yes, they are thread-safe.

Two things that give it away:

- It are systemcalls, and those are always thread safe (on any sane system).

- They take a pointer to a structure you allocated, so they don't do any memory handling, but only touch what you give them.

Of course most thread-safe functions can be used in a non-thread-safe way.