on Linux, while executing sem_timewait (), will the current thread sleep, choose another thread to execute, or block in place until it times out?
after the timeout, if the lock has not been acquired, do you sleep or block the current process?
on Linux, while executing sem_timewait (), will the current thread sleep, choose another thread to execute, or block in place until it times out?
after the timeout, if the lock has not been acquired, do you sleep or block the current process?
if you are talking about sem_timedwait
:
as far as I can remember, only spin locks block in place, while other Synchronize mechanisms sleep.
the second problem is mentioned in the man manual. When the timeout has not yet acquired the lock, the function will return an error failure of timeout, and errno will set ETIMEDOUT
.If the timeout has already expired by the time of the call, and the semaphore could not be locked immediately, then sem_timedwait () fails with a timeout error (errno set to ETIMEDOUT).
sem_timewait function blocks the current thread until it gets the lock or times out. Blocking is implemented by sleeping the current thread until the lock is released or wakes up after the timeout. After the
timeout, this function returns to continue executing the following code, which logically determines the subsequent behavior.
hibernation is an implementation or expression of blocking, and the two are not the same level of concept.