有没有人能为我澄清一下以下代码段是否具有线程安全性?
int get_time(uint64_t *time)
{
struct timespec spec;
if (!time)
return -EFAULT;
if (clock_gettime(CLOCK_REALTIME, &spec) == -1)
return -errno;
*time = //convert timespec into nanoseconds
return SUCCESS;
}
这是一个库中可由多个线程调用的API。规范是一个局部变量,所以不应该存在问题。正确吗?我的疑问在于clock_getime(POSIX.1-2001)和对时间参数的赋值。我想引入一个互斥锁,但我不确定是否严格需要。
clock_gettime()
为什么会不支持多线程呢? - Iharob Al Asimi