The sem_timedwait function locks the semaphore referenced by sem as in the sem_wait function. But if the semaphore cannot be locked without waiting for another process or thread to unlock the semaphore by performing a sem_post function, this wait terminates when the specified timeout expires. The timeout expires when the absolute time specified by abs_ timeout passes, as measured by the clock on which timeouts are based (that is, when the value of that clock equals or exceeds abs_timeout, or if the absolute time specified by abs_timeout has already been passed at the time of the call. The function will not fail with a timeout if the semaphore can be locked immediately. The validity of abs_timeout does not need to be checked if the semaphore can be locked immediately.