虚假唤醒的 return 值是多少?
What is the return value of spurious wake-ups?
在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
or cnd_broadcast
, or until the TIME_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, or thrd_error
if an error occurred.
当虚假唤醒发生时,函数 return thrd_success
或 thrd_error
?
虽然据我所知,虚假唤醒在技术上并不被视为错误。
如果 cnd_timedwait
可以判断唤醒是虚假的,它就不会这样做。它不会为了欺骗您而进行虚假唤醒。它们的发生是因为条件的值可以在计划唤醒之后但在被唤醒的线程设法做任何事情之前发生变化。
由于 cnd_timedwait
无法判断 return 是否虚假,因此 return 值无法反映这一事实。正常成功return。您的首要任务是验证条件。
在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.
当虚假唤醒发生时,函数 return thrd_success
或 thrd_error
?
虽然据我所知,虚假唤醒在技术上并不被视为错误。
如果 cnd_timedwait
可以判断唤醒是虚假的,它就不会这样做。它不会为了欺骗您而进行虚假唤醒。它们的发生是因为条件的值可以在计划唤醒之后但在被唤醒的线程设法做任何事情之前发生变化。
由于 cnd_timedwait
无法判断 return 是否虚假,因此 return 值无法反映这一事实。正常成功return。您的首要任务是验证条件。