[英]Is the gettimeofday function thread safe in Linux?
必须全局存储当前时间才能使gettimeofday正常工作,但我不确定该函数是否修改了任何全局状态,以便并发执行未定义。
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. 祝你的项目好运。
In glibc
the gettimeofday(2)
is a simple wrapper around a system call (it's a vsyscall
actually). 在glibc
, gettimeofday(2)
是一个围绕系统调用的简单包装器(实际上是vsyscall
)。 No data is touched in the userland. 用户区中未触及任何数据。 It is thread-safe. 它是线程安全的。
No data is modified with this call. 此调用未修改任何数据。 You just get a copy. 你得到一份副本。 Hence its completely thread safe. 因此它完全线程安全。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.