Is the gettimeofday function thread safe in Linux?

后端 未结 4 2096
无人共我
无人共我 2020-12-17 23:00

The current time must be stored globally in order for gettimeofday to work, however I am not sure if the function modifies any global state so that concurrent execution is u

相关标签:
4条回答
  • 2020-12-17 23:44

    No data is modified with this call. You just get a copy. Hence its completely thread safe.

    0 讨论(0)
  • gettimeofday is thread safe.

    The (posix) functions listed here might not be, gettimeofday is not one of them.

    0 讨论(0)
  • 2020-12-17 23:57

    In glibc the gettimeofday(2) is a simple wrapper around a system call (it's a vsyscall actually). No data is touched in the userland. It is thread-safe.

    0 讨论(0)
  • 2020-12-18 00:00

    Yes, it is thread-safe. The only data it modifies is in the structures you pass pointers to, so an implementation that wasn't thread-safe would have to be doing something spooky.

    Best of luck on your project.

    0 讨论(0)
提交回复
热议问题