第二个问题在 man 手册中有提到,当超时还没有获得锁,函数会以 timeout 的错误失败返回,errno 会设置 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_timedwait
:我印象中,只有自旋锁会在原地阻塞,而其他同步机制都是会睡眠。
第二个问题在 man 手册中有提到,当超时还没有获得锁,函数会以 timeout 的错误失败返回,errno 会设置 ETIMEDOUT