【发布时间】:2020-04-21 04:37:27
【问题描述】:
在C11中,cnd_timedwait函数定义如下:
int cnd_timedwait( cnd_t* restrict cond, mtx_t* restrict mutex, const struct timespec* restrict time_point );自动解锁 mutex 指向的 mutex 并阻塞 cond 指向的条件变量,直到线程由
cnd_signal或cnd_broadcast发出信号,或直到 time_point 指向的基于TIME_UTC的时间点已被达到,或直到发生虚假唤醒。在函数返回之前,互斥锁再次被锁定。返回值
thrd_success如果成功,thrd_timedout如果在互斥锁被锁定之前已经达到超时时间,或者thrd_error如果发生错误。
发生虚假唤醒时,函数会返回thrd_success 还是thrd_error?
尽管据我所知,虚假唤醒在技术上并不被视为错误。
【问题讨论】:
-
reference for the equivalent C++ function 更详细地记录了虚假唤醒的影响。它还具有处理它们的重载(使用显示您应该做什么的等效代码)。
标签: c multithreading posix c11