在C11中,cnd_timedwait
函数定义如下:
int cnd_timedwait( cnd_t* restrict cond, mtx_t* restrict mutex, const struct timespec* restrict time_point );
Atomically unlocks the mutex pointed to by mutex and blocks on the condition variable pointed to by cond until the thread is signalled by
cnd_signal
orcnd_broadcast
, or until theTIME_UTC
based time point pointed to by time_point has been reached, or until a spurious wake-up occurs. The mutex is locked again before the function returns.Return value
thrd_success
if successful,thrd_timedout
if the timeout time has been reached before the mutex is locked, orthrd_error
if an error occurred.
当虚假唤醒发生时,函数会返回thrd_success
还是thrd_error
?
尽管据我所知,虚假唤醒在技术上不被视为错误。
最佳答案
如果 cnd_timedwait
可以判断唤醒是虚假的,它就不会这样做。它不会为了欺骗您而进行虚假唤醒。它们的发生是因为条件的值可以在计划唤醒之后但在被唤醒的线程设法做任何事情之前发生变化。
由于 cnd_timedwait
无法判断返回是否虚假,因此它的返回值无法反射(reflect)这一事实。这是正常的成功返回。您的首要任务是验证条件。
关于c - 虚假唤醒的返回值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59564596/